INT_MIN {/,%} -1 = INT_MAX for our purposes.
[exim.git] / src / src / moan.c
index 4503a47e5ed9c6ac6f9d4d711b537d17719fb630..ff6c3682645733e0b376565d21e046c25b6b99ac 100644 (file)
@@ -1,10 +1,10 @@
-/* $Cambridge: exim/src/src/moan.c,v 1.7 2007/01/08 10:50:18 ph10 Exp $ */
+/* $Cambridge: exim/src/src/moan.c,v 1.11 2009/11/16 19:50:37 nm4 Exp $ */
 
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
 
-/* Copyright (c) University of Cambridge 1995 - 2007 */
+/* Copyright (c) University of Cambridge 1995 - 2009 */
 /* See the file NOTICE for conditions of use and distribution. */
 
 /* Functions for sending messages to sender or to mailmaster. */
 
 
 
+/*************************************************
+*            Write From: line for DSN            *
+*************************************************/
+
+/* This function is called to write the From: line in automatically generated
+messages - bounces, warnings, etc. It expands a configuration item in order to
+get the text. If the expansion fails, a panic is logged and the default value
+for the option is used.
+
+Argument:   the FILE to write to
+Returns:    nothing
+*/
+
+void
+moan_write_from(FILE *f)
+{
+uschar *s = expand_string(dsn_from);
+if (s == NULL)
+  {
+  log_write(0, LOG_MAIN|LOG_PANIC,
+    "Failed to expand dsn_from (using default): %s", expand_string_message);
+  s = expand_string(US DEFAULT_DSN_FROM);
+  }
+fprintf(f, "From: %s\n", s);
+}
+
+
+
 /*************************************************
 *              Send error message                *
 *************************************************/
@@ -62,8 +90,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-replied\n");
-fprintf(f, "From: Mail Delivery System <Mailer-Daemon@%s>\n",
-  qualify_domain_sender);
+moan_write_from(f);
 fprintf(f, "To: %s\n", recipient);
 
 switch(ident)
@@ -410,8 +437,8 @@ Returns:        nothing
 */
 
 void
-moan_tell_someone(uschar *who, address_item *addr, uschar *subject,
-  char *format, ...)
+moan_tell_someone(uschar *who, address_item *addr,
+  const uschar *subject, const char *format, ...)
 {
 FILE *f;
 va_list ap;
@@ -427,8 +454,7 @@ if (pid < 0)
 
 f = fdopen(fd, "wb");
 fprintf(f, "Auto-Submitted: auto-replied\n");
-fprintf(f, "From: Mail Delivery System <Mailer-Daemon@%s>\n",
-  qualify_domain_sender);
+moan_write_from(f);
 fprintf(f, "To: %s\n", who);
 fprintf(f, "Subject: %s\n\n", subject);
 va_start(ap, format);
@@ -479,7 +505,7 @@ Returns:       does not return; exits from the program
 */
 
 void
-moan_smtp_batch(uschar *cmd_buffer, char *format, ...)
+moan_smtp_batch(uschar *cmd_buffer, const char *format, ...)
 {
 va_list ap;
 int yield = (receive_messagecount > 0)? 1 : 2;
@@ -558,7 +584,7 @@ if (errors_copy == NULL) return NULL;
 length of the local part. */
 
 localpart = recipient;
-domain = Ustrchr(recipient, '@');
+domain = Ustrrchr(recipient, '@');
 if (domain == NULL) return NULL;  /* should not occur, but avoid crash */
 llen = domain++ - recipient;
 
@@ -584,10 +610,7 @@ while ((item = string_nextinlist(&listptr, &sep, buffer, sizeof(buffer)))
   if (match_address_list(recipient, TRUE, TRUE, &pattern, NULL, 0, UCHAR_MAX+1,
         NULL) == OK)
     {
-    uschar temp[256];
-    Ustrncpy(temp, localpart, llen);
-    temp[llen] = 0;
-    deliver_localpart = temp;
+    deliver_localpart = string_copyn(localpart, llen);
     deliver_domain = domain;
     yield = expand_string_copy(newaddress);
     deliver_domain = deliver_localpart = NULL;
@@ -671,8 +694,7 @@ if (pid < 0)
 
 f = fdopen(fd, "wb");
 fprintf(f, "Auto-Submitted: auto-replied\n");
-fprintf(f, "From: Mail Delivery System <Mailer-Daemon@%s>\n",
-  qualify_domain_sender);
+moan_write_from(f);
 fprintf(f, "To: %s\n", s);
 fprintf(f, "Subject: error(s) in forwarding or filtering\n\n");