Update version number and copyright year.
[exim.git] / src / src / moan.c
index 8591281999c8f270566a8c9c347c2fa9db85bbb6..4503a47e5ed9c6ac6f9d4d711b537d17719fb630 100644 (file)
@@ -1,10 +1,10 @@
-/* $Cambridge: exim/src/src/moan.c,v 1.2 2005/01/04 10:00:42 ph10 Exp $ */
+/* $Cambridge: exim/src/src/moan.c,v 1.7 2007/01/08 10:50:18 ph10 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2005 */
+/* Copyright (c) University of Cambridge 1995 - 2007 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* Functions for sending messages to sender or to mailmaster. */
@@ -61,7 +61,7 @@ else DEBUG(D_any) debug_printf("Child process %d for sending message\n", pid);
 
 f = fdopen(fd, "wb");
 if (errors_reply_to != NULL) fprintf(f, "Reply-To: %s\n", errors_reply_to);
-fprintf(f, "Auto_submitted: auto-generated\n");
+fprintf(f, "Auto-Submitted: auto-replied\n");
 fprintf(f, "From: Mail Delivery System <Mailer-Daemon@%s>\n",
   qualify_domain_sender);
 fprintf(f, "To: %s\n", recipient);
@@ -185,62 +185,74 @@ switch(ident)
   break;
   }
 
-/* Now copy the message - headers then the rest of the input if
-available, up to the configured limit. */
+/* Now, if configured, copy the message; first the headers and then the rest of
+the input if available, up to the configured limit, if the option for including
+message bodies in bounces is set. */
 
-if (size_limit == 0 || size_limit > thismessage_size_limit)
-  size_limit = thismessage_size_limit;
-
-if (size_limit > 0 && size_limit < message_size)
+if (bounce_return_message)
   {
-  int x = size_limit;
-  uschar *k = US"";
-  if ((x & 1023) == 0)
+  if (bounce_return_body)
     {
-    k = US"K";
-    x >>= 10;
+    fprintf(f, "\n"
+      "------ This is a copy of your message, including all the headers.");
+    if (size_limit == 0 || size_limit > thismessage_size_limit)
+      size_limit = thismessage_size_limit;
+    if (size_limit > 0 && size_limit < message_size)
+      {
+      int x = size_limit;
+      uschar *k = US"";
+      if ((x & 1023) == 0)
+        {
+        k = US"K";
+        x >>= 10;
+        }
+      fprintf(f, "\n"
+        "------ No more than %d%s characters of the body are included.\n\n",
+          x, k);
+      }
+    else fprintf(f, " ------\n\n");
+    }
+  else
+    {
+    fprintf(f, "\n"
+      "------ This is a copy of the headers that were received before the "
+      "error\n       was detected.\n\n");
     }
-  fprintf(f, "\n"
-  "------ This is a copy of your message, including all the headers.\n"
-  "------ No more than %d%s characters of the body are included.\n\n", x, k);
-  }
-else fprintf(f, "\n"
-  "------ This is a copy of your message, including all the headers. ------"
-  "\n\n");
 
-/* If the error occurred before the Received: header was created, its text
-field will still be NULL; just omit such a header line. */
+  /* If the error occurred before the Received: header was created, its text
+  field will still be NULL; just omit such a header line. */
 
-while (headers != NULL)
-  {
-  if (headers->text != NULL) fprintf(f, "%s", CS headers->text);
-  headers = headers->next;
-  }
+  while (headers != NULL)
+    {
+    if (headers->text != NULL) fprintf(f, "%s", CS headers->text);
+    headers = headers->next;
+    }
 
-if (ident != ERRMESS_VLONGHEADER && ident != ERRMESS_VLONGHDRLINE)
-  fputc('\n', f);
+  if (ident != ERRMESS_VLONGHEADER && ident != ERRMESS_VLONGHDRLINE)
+    fputc('\n', f);
 
-/* After early detection of an error, the message file may be STDIN,
-in which case we might have to terminate on a line containing just "."
-as well as on EOF. We may already have the first line in memory. */
+  /* After early detection of an error, the message file may be STDIN,
+  in which case we might have to terminate on a line containing just "."
+  as well as on EOF. We may already have the first line in memory. */
 
-if (message_file != NULL)
-  {
-  int ch;
-  int state = 1;
-  BOOL enddot = dot_ends && message_file == stdin;
-  if (firstline != NULL) fprintf(f, "%s", CS firstline);
-  while ((ch = fgetc(message_file)) != EOF)
+  if (bounce_return_body && message_file != NULL)
     {
-    fputc(ch, f);
-    if (size_limit > 0 && ++written > size_limit) break;
-    if (enddot)
+    int ch;
+    int state = 1;
+    BOOL enddot = dot_ends && message_file == stdin;
+    if (firstline != NULL) fprintf(f, "%s", CS firstline);
+    while ((ch = fgetc(message_file)) != EOF)
       {
-      if (state == 0) { if (ch == '\n') state = 1; }
-      else if (state == 1)
-        { if (ch == '.') state = 2; else if (ch != '\n') state = 0; }
-      else
-        { if (ch == '\n') break; else state = 0; }
+      fputc(ch, f);
+      if (size_limit > 0 && ++written > size_limit) break;
+      if (enddot)
+        {
+        if (state == 0) { if (ch == '\n') state = 1; }
+        else if (state == 1)
+          { if (ch == '.') state = 2; else if (ch != '\n') state = 0; }
+        else
+          { if (ch == '\n') break; else state = 0; }
+        }
       }
     }
   }
@@ -248,7 +260,7 @@ if (message_file != NULL)
 /* Close the file, which should send an EOF to the child process
 that is receiving the message. Wait for it to finish, without a timeout. */
 
-fclose(f);
+(void)fclose(f);
 status = child_close(pid, 0);  /* Waits for child to close */
 if (status != 0)
   {
@@ -414,7 +426,7 @@ if (pid < 0)
   }
 
 f = fdopen(fd, "wb");
-fprintf(f, "Auto_submitted: auto-generated\n");
+fprintf(f, "Auto-Submitted: auto-replied\n");
 fprintf(f, "From: Mail Delivery System <Mailer-Daemon@%s>\n",
   qualify_domain_sender);
 fprintf(f, "To: %s\n", who);
@@ -437,7 +449,7 @@ if (addr != NULL)
     }
   }
 
-fclose(f);
+(void)fclose(f);
 child_close(pid, 0);  /* Waits for child to close; no timeout */
 }
 
@@ -658,7 +670,7 @@ if (pid < 0)
   }
 
 f = fdopen(fd, "wb");
-fprintf(f, "Auto_submitted: auto-generated\n");
+fprintf(f, "Auto-Submitted: auto-replied\n");
 fprintf(f, "From: Mail Delivery System <Mailer-Daemon@%s>\n",
   qualify_domain_sender);
 fprintf(f, "To: %s\n", s);
@@ -692,7 +704,7 @@ if (some)
 else
   fprintf(f, "No valid addresses were generated.\n");
 
-fclose(f);
+(void)fclose(f);
 child_close(pid, 0);  /* Waits for child to close; no timeout */
 
 return TRUE;