Update $message_linecount for maildir_tag.
authorPhil Pennock <pdp@exim.org>
Mon, 21 Feb 2011 04:44:50 +0000 (23:44 -0500)
committerPhil Pennock <pdp@exim.org>
Mon, 21 Feb 2011 04:45:22 +0000 (23:45 -0500)
Patch from Mark Zealey.
Fixes bug 1055.

doc/doc-docbook/spec.xfpt
doc/doc-txt/ChangeLog
doc/doc-txt/NewStuff
src/src/globals.c
src/src/globals.h
src/src/transport.c
src/src/transports/appendfile.c

index bc9dd2e145442ab1f7e77a06be4a7377ef8cd414..15f104d2bd8d365902f9f081ebc3f6be2d816bba 100644 (file)
@@ -11137,8 +11137,15 @@ number of lines received. Before delivery happens (that is, before filters,
 routers, and transports run) the count is increased to include the
 &'Received:'& header line that Exim standardly adds, and also any other header
 lines that are added by ACLs. The blank line that separates the message header
 routers, and transports run) the count is increased to include the
 &'Received:'& header line that Exim standardly adds, and also any other header
 lines that are added by ACLs. The blank line that separates the message header
-from the body is not counted. Here is an example of the use of this variable in
-a DATA ACL:
+from the body is not counted.
+
+As with the special case of &$message_size$&, during the expansion of the
+appendfile transport's maildir_tag option in maildir format, the value of
+&$message_linecount$& is the precise size of the number of newlines in the
+file that has been written (minus one for the blank line between the
+header and the body).
+
+Here is an example of the use of this variable in a DATA ACL:
 .code
 deny message   = Too many lines in message header
      condition = \
 .code
 deny message   = Too many lines in message header
      condition = \
index 862f1b887a650a3bda9f6ebd379d82ce4fb1d867..1fd7bd3cf5fd05710ac04ae7cca5efcb95c94c77 100644 (file)
@@ -60,6 +60,9 @@ PP/10 Use sig_atomic_t for flags set from signal handlers.
       Fixed developed for diagnosis in bug 927 (which turned out to be
       a kernel bug).
 
       Fixed developed for diagnosis in bug 927 (which turned out to be
       a kernel bug).
 
+PP/11 Bugzilla 1055: Update $message_linecount for maildir_tag.
+      Patch from Mark Zealey.
+
 
 Exim version 4.74
 -----------------
 
 Exim version 4.74
 -----------------
index 6159bf4433d0c80c8fe108d42f77b179807fc644..7ae550bb43954841db7babdcaa5d13f3a9b7b48e 100644 (file)
@@ -25,6 +25,10 @@ Version 4.75
  3. Log filenames may now use %M as an escape, instead of %D (still available).
     The %M pattern expands to yyyymm, providing month-level resolution.
 
  3. Log filenames may now use %M as an escape, instead of %D (still available).
     The %M pattern expands to yyyymm, providing month-level resolution.
 
+ 4. The $message_linecount variable is now updated for the maildir_tag option,
+    in the same way as $message_size, to reflect the real number of lines,
+    including any header additions or removals from transport.
+
 
 Version 4.74
 ------------
 
 Version 4.74
 ------------
index 60ef8e0a8c57563007d2d8bf68b8812bbaafcdc3..fe3a2eeb53bb2bddec964fb297fb871a31d96011 100644 (file)
@@ -1254,6 +1254,7 @@ transport_instance  transport_defaults = {
 };
 
 int     transport_count;
 };
 
 int     transport_count;
+int     transport_newlines;
 uschar **transport_filter_argv  = NULL;
 int     transport_filter_timeout;
 BOOL    transport_filter_timed_out = FALSE;
 uschar **transport_filter_argv  = NULL;
 int     transport_filter_timeout;
 BOOL    transport_filter_timed_out = FALSE;
index 1f0463264c234fb2419517fa553885c04c3d5fc2..b0c26c42501d0393d6abf7ef6a783ca4887a42b2 100644 (file)
@@ -785,6 +785,7 @@ extern int     thismessage_size_limit; /* Limit for this message */
 extern int     timeout_frozen_after;   /* Max time to keep frozen messages */
 extern BOOL    timestamps_utc;         /* Use UTC for all times */
 extern int     transport_count;        /* Count of bytes transported */
 extern int     timeout_frozen_after;   /* Max time to keep frozen messages */
 extern BOOL    timestamps_utc;         /* Use UTC for all times */
 extern int     transport_count;        /* Count of bytes transported */
+extern int     transport_newlines;     /* Accurate count of number of newline chars transported */
 extern uschar **transport_filter_argv; /* For on-the-fly filtering */
 extern int     transport_filter_timeout; /* Timeout for same */
 extern BOOL    transport_filter_timed_out; /* True if it did */
 extern uschar **transport_filter_argv; /* For on-the-fly filtering */
 extern int     transport_filter_timeout; /* Timeout for same */
 extern BOOL    transport_filter_timed_out; /* True if it did */
index e68a24dcbe7a4d313fdc4db112e132fd6a240217..504ef9e06aaa2f8fbd994d46dd1764655b192f58 100644 (file)
@@ -426,6 +426,7 @@ for (ptr = start; ptr < end; ptr++)
 
     if (use_crlf) *chunk_ptr++ = '\r';
     *chunk_ptr++ = '\n';
 
     if (use_crlf) *chunk_ptr++ = '\r';
     *chunk_ptr++ = '\n';
+    transport_newlines++;
 
     /* The check_string test (formerly "from hack") replaces the specific
     string at the start of a line with an escape string (e.g. "From " becomes
 
     /* The check_string test (formerly "from hack") replaces the specific
     string at the start of a line with an escape string (e.g. "From " becomes
index e537615824300233b47cb9d5425cf461c7a38d6b..6dbb352629dd511f114526327a3907f147a846a3 100644 (file)
@@ -2782,6 +2782,7 @@ if (yield == OK && ob->mbx_format)
 functions. */
 
 transport_count = 0;
 functions. */
 
 transport_count = 0;
+transport_newlines = 0;
 
 /* Write any configured prefix text first */
 
 
 /* Write any configured prefix text first */
 
@@ -2807,21 +2808,26 @@ file, use its parent in the RCPT TO. */
 if (yield == OK && ob->use_bsmtp)
   {
   transport_count = 0;
 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;
   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; }
     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;
       }
     if (yield == OK && !transport_write_string(fd, "DATA%s\n", cr))
       yield = DEFER;
+    else
+      transport_newlines++;
     }
   }
 
     }
   }
 
@@ -2854,8 +2860,10 @@ if (yield == OK && ob->message_suffix != NULL && ob->message_suffix[0] != 0)
 
 /* If batch smtp, write the terminating dot. */
 
 
 /* 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 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),
@@ -2873,6 +2881,8 @@ if (temp_file != NULL && ob->mbx_format)
   if (yield == OK)
     {
     transport_count = 0;   /* Reset transport count for actual write */
   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";
     yield = copy_mbx_message(fd, fileno(temp_file), saved_size);
     }
   else if (errno >= 0) dataname = US"temporary file";
@@ -2890,10 +2900,13 @@ fsync() to be called for a FIFO. */
 
 if (yield == OK && !isfifo && EXIMfsync(fd) < 0) yield = DEFER;
 
 
 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_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 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