mbox-save.c revision a8a89d6265c9bbaf814d8146c93e39609d6e4da2
/* Copyright (C) 2002-2007 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "base64.h"
#include "hostpid.h"
#include "randgen.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
#include "write-full.h"
#include "istream-header-filter.h"
#include "ostream-crlf.h"
#include "message-parser.h"
#include "index-mail.h"
#include "mbox-storage.h"
#include "mbox-file.h"
#include "mbox-from.h"
#include "mbox-lock.h"
#include "mbox-md5.h"
#include "mbox-sync-private.h"
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
struct mbox_save_context {
struct mail_save_context ctx;
struct mbox_mailbox *mbox;
struct mail_index_transaction *trans;
char last_char;
struct mbox_md5_context *mbox_md5_ctx;
unsigned int synced:1;
unsigned int failed:1;
unsigned int finished:1;
};
{
"Not enough disk space");
} else {
}
}
{
char ch;
int fd;
*offset = 0;
return 0;
}
return 0;
if (ch != '\n') {
return -1;
}
*offset += 1;
}
return 0;
}
{
return -1;
}
return 0;
}
const char *from_envelope)
{
int ret;
if (*my_hostdomain == '\0') {
/* failed, use just the hostname */
name = my_hostname;
}
}
t_push();
if (from_envelope == NULL) {
}
/* save in local timezone, no matter what it was given with */
t_pop();
return ret;
}
{
const char *str;
int ret = 0;
/* we can't seek, don't set Content-Length */
return 0;
}
/* write Content-Length headers */
t_push();
ret = -1;
ret = -1;
} else {
ret = -1;
}
}
t_pop();
return ret;
}
static void mbox_save_init_sync(struct mbox_transaction_context *t)
{
const struct mail_index_header *hdr;
struct mail_index_view *view;
/* open a new view to get the header. this is required if we just
synced the mailbox so we can get updated next_uid. */
t->mbox_modified = TRUE;
}
const struct mbox_flag_type *flags_list)
{
int i;
for (i = 0; flags_list[i].chr != 0; i++) {
}
}
{
if ((flags & STATUS_FLAGS_MASK) != 0) {
}
if ((flags & XSTATUS_FLAGS_MASK) != 0) {
}
}
static void
struct mail_keywords *keywords)
{
const char *const *keyword_names;
unsigned int i, count, keyword_names_count;
for (i = 0; i < count; i++) {
}
}
static int
struct mbox_transaction_context *t, bool want_mail)
{
int ret;
"Read-only mbox");
return -1;
}
/* first appended mail in this transaction */
/* FIXME: we shouldn't fail here. it's just
a locking issue that should be possible to
fix.. */
"Can't copy mails inside same mailbox");
return -1;
}
return -1;
}
if (mbox_file_open(mbox) < 0)
return -1;
}
if (!want_mail) {
/* assign UIDs only if mbox doesn't require syncing */
if (ret < 0)
return -1;
if (ret == 0)
}
return -1;
0, FALSE);
}
/* we'll need to assign UID for the mail immediately. */
return -1;
}
return 0;
}
{
/* we can't allow From_-lines in headers. there's no
legitimate reason for allowing them in any case,
so just drop them. */
return;
}
}
}
}
{
unsigned char md5_result[MD5_RESULTLEN];
void *randbuf;
t_push();
sizeof(ioloop_timeval.tv_usec));
t_pop();
}
{
struct mbox_transaction_context *t =
(struct mbox_transaction_context *)_t;
enum mail_flags save_flags;
/* FIXME: we could write timezone_offset to From-line.. */
}
return -1;
}
/* writing the first mail. Insert X-IMAPbase as well. */
}
MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) != 0) {
/* we're using MD5 sums to generate POP3 UIDLs.
clients don't like it much if there are duplicates,
so make sure that there can't be any by appending
our own X-Delivery-ID header. */
}
save_flags &= ~MAIL_RECENT;
}
/* parse and cache the mail headers as we read it */
}
i_unreached();
NULL);
}
else {
ctx->body_output =
MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ?
}
}
{
const unsigned char *data;
return -1;
/* writing body */
if (ret == 0)
return 0;
return -1;
}
}
/* if mail doesn't end with LF, we'll do that.
otherwise some mbox parsers don't like the result.
this makes it impossible to save a mail that doesn't
end with LF though. */
return -1;
}
}
return 0;
}
if (ret == 0)
return 0;
/* found end of headers. write the rest of them. */
return -1;
}
if (size > 0)
break;
}
return -1;
}
}
return -1;
}
}
if (ctx->mbox_md5_ctx) {
unsigned char hdr_md5_sum[16];
hdr_md5_sum, NULL);
}
/* append our own headers and ending empty line */
return -1;
}
/* write body */
}
{
if (mbox_write_content_length(ctx) < 0 ||
mbox_append_lf(ctx) < 0)
}
/* saving this mail failed - truncate back to beginning of it */
}
}
{
(void)mbox_save_finish(_ctx);
}
{
}
{
int ret = 0;
ret = -1;
} else {
}
}
ret = -1;
}
}
return ret;
}
{
/* failed, truncate file back to original size.
output stream needs to be flushed before truncating
so unref() won't write anything. */
}
}