-/* $Cambridge: exim/src/src/transports/appendfile.c,v 1.26 2010/05/29 12:11:48 pdp Exp $ */
-
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
enum { mbf_unix, mbf_mbx, mbf_smail, mbf_maildir, mbf_mailstore };
-static char *mailbox_formats[] = {
+static const char *mailbox_formats[] = {
"unix", "mbx", "smail", "maildir", "mailstore" };
opt_public flag. */
optionlist appendfile_transport_options[] = {
+#ifdef SUPPORT_MAILDIR
+ { "*expand_maildir_use_size_file", opt_stringptr,
+ (void *)offsetof(appendfile_transport_options_block, expand_maildir_use_size_file) },
+#endif
{ "*set_use_fcntl_lock",opt_bool | opt_hidden,
(void *)offsetof(appendfile_transport_options_block, set_use_fcntl) },
{ "*set_use_flock_lock",opt_bool | opt_hidden,
(void *)offsetof(appendfile_transport_options_block, maildir_retries) },
{ "maildir_tag", opt_stringptr,
(void *)offsetof(appendfile_transport_options_block, maildir_tag) },
- { "maildir_use_size_file", opt_bool,
+ { "maildir_use_size_file", opt_expand_bool,
(void *)offsetof(appendfile_transport_options_block, maildir_use_size_file ) } ,
{ "maildirfolder_create_regex", opt_stringptr,
(void *)offsetof(appendfile_transport_options_block, maildirfolder_create_regex ) },
NULL, /* quota_warn_threshold */
NULL, /* mailbox_size_string */
NULL, /* mailbox_filecount_string */
+ NULL, /* expand_maildir_use_size_file */
US"^(?:cur|new|\\..*)$", /* maildir_dir_regex */
NULL, /* maildir_tag */
NULL, /* maildirfolder_create_regex */
uid = uid;
gid = gid;
+if (ob->expand_maildir_use_size_file)
+ ob->maildir_use_size_file = expand_check_condition(ob->expand_maildir_use_size_file,
+ US"`maildir_use_size_file` in transport", tblock->name);
+
/* Loop for quota, quota_filecount, quota_warn_threshold, mailbox_size,
mailbox_filecount */
goto RETURN;
}
- if (lstat(mbx_lockname, &lstatbuf) < 0)
+ if (Ulstat(mbx_lockname, &lstatbuf) < 0)
{
addr->basic_errno = ERRNO_LOCKFAILED;
addr->message = string_sprintf("attempting to lstat open MBX "
"%s/maildirsize", check_path);
return FALSE;
}
+ /* can also return -2, which means that the file was removed because of
+ raciness; but in this case, the size & filecount will still have been
+ updated. */
if (mailbox_size < 0) mailbox_size = size;
if (mailbox_filecount < 0) mailbox_filecount = filecount;
functions. */
transport_count = 0;
+transport_newlines = 0;
/* Write any configured prefix text first */
if (yield == OK && ob->use_bsmtp)
{
transport_count = 0;
+ transport_newlines = 0;
if (ob->use_crlf) cr = US"\r";
if (!transport_write_string(fd, "MAIL FROM:<%s>%s\n", return_path, cr))
yield = DEFER;
else
{
address_item *a;
+ transport_newlines++;
for (a = addr; a != NULL; a = a->next)
{
address_item *b = testflag(a, af_pfr)? a->parent: a;
if (!transport_write_string(fd, "RCPT TO:<%s>%s\n",
transport_rcpt_address(b, tblock->rcpt_include_affixes), cr))
{ yield = DEFER; break; }
+ transport_newlines++;
}
if (yield == OK && !transport_write_string(fd, "DATA%s\n", cr))
yield = DEFER;
+ else
+ transport_newlines++;
}
}
/* If batch smtp, write the terminating dot. */
-if (yield == OK && ob->use_bsmtp &&
- !transport_write_string(fd, ".%s\n", cr)) yield = DEFER;
+if (yield == OK && ob->use_bsmtp ) {
+ if(!transport_write_string(fd, ".%s\n", cr)) yield = DEFER;
+ else transport_newlines++;
+}
/* If MBX format is being used, all that writing was to the temporary file.
However, if there was an earlier failure (Exim quota exceeded, for example),
if (yield == OK)
{
transport_count = 0; /* Reset transport count for actual write */
+ /* No need to reset transport_newlines as we're just using a block copy
+ * routine so the number won't be affected */
yield = copy_mbx_message(fd, fileno(temp_file), saved_size);
}
else if (errno >= 0) dataname = US"temporary file";
if (yield == OK && !isfifo && EXIMfsync(fd) < 0) yield = DEFER;
-/* Update message_size to the accurate count of bytes written, including
-added headers. */
+/* Update message_size and message_linecount to the accurate count of bytes
+written, including added headers. Note; we subtract 1 from message_linecount as
+this variable doesn't count the new line between the header and the body of the
+message. */
message_size = transport_count;
+message_linecount = transport_newlines - 1;
/* If using a maildir++ quota file, add this message's size to it, and
close the file descriptor, except when the quota has been disabled because we
if (yield == OK && maildirsize_fd >= 0)
maildir_record_length(maildirsize_fd, message_size);
maildir_save_errno = errno; /* Preserve errno while closing the file */
- (void)close(maildirsize_fd);
+ if (maildirsize_fd >= 0)
+ (void)close(maildirsize_fd);
errno = maildir_save_errno;
}
#endif /* SUPPORT_MAILDIR */