[dovecot-cvs] dovecot/src/deliver deliver.c,1.20.2.10,1.20.2.11

tss at dovecot.org tss at dovecot.org
Sun Oct 8 20:24:38 UTC 2006


Update of /var/lib/cvs/dovecot/src/deliver
In directory talvi:/tmp/cvs-serv22617

Modified Files:
      Tag: branch_1_0
	deliver.c 
Log Message:
Added -f parameter to specify the envelope sender which is used in mbox
From-lines.



Index: deliver.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/deliver/deliver.c,v
retrieving revision 1.20.2.10
retrieving revision 1.20.2.11
diff -u -d -r1.20.2.10 -r1.20.2.11
--- deliver.c	22 Sep 2006 14:29:20 -0000	1.20.2.10
+++ deliver.c	8 Oct 2006 19:24:36 -0000	1.20.2.11
@@ -30,6 +30,7 @@
 #define DEFAULT_CONFIG_FILE SYSCONFDIR"/dovecot.conf"
 #define DEFAULT_AUTH_SOCKET_PATH PKG_RUNDIR"/auth-master"
 #define DEFAULT_SENDMAIL_PATH "/usr/lib/sendmail"
+#define DEFAULT_ENVELOPE_SENDER "dovecot.deliver"
 
 /* After buffer grows larger than this, create a temporary file to /tmp
    where to read the mail. */
@@ -135,7 +136,7 @@
 	addr = str == NULL ? NULL :
 		message_address_parse(pool_datastack_create(),
 				      (const unsigned char *)str,
-				      strlen(str), 1);
+				      strlen(str), 1, FALSE);
 	return addr == NULL || addr->mailbox == NULL || addr->domain == NULL ?
 		NULL : t_strconcat(addr->mailbox, "@", addr->domain, NULL);
 }
@@ -293,14 +294,36 @@
 	return str_c(str);
 }
 
-static struct istream *create_mbox_stream(int fd)
+static const char *address_sanitize(const char *address)
+{
+	struct message_address *addr;
+	const char *ret;
+	pool_t pool;
+
+	pool = pool_alloconly_create("address sanitizer", 128);
+	addr = message_address_parse(pool, (const unsigned char *)address,
+				     strlen(address), 1, FALSE);
+
+	if (addr->mailbox == NULL || addr->domain == NULL ||
+	    *addr->mailbox == '\0')
+		ret = DEFAULT_ENVELOPE_SENDER;
+	else if (*addr->domain == '\0')
+		ret = t_strdup(addr->mailbox);
+	else
+		ret = t_strdup_printf("%s@%s", addr->mailbox, addr->domain);
+	pool_unref(pool);
+	return ret;
+}
+
+static struct istream *create_mbox_stream(int fd, const char *envelope_sender)
 {
 	const char *mbox_hdr;
 	struct istream *input_list[4], *input;
 
 	fd_set_nonblock(fd, FALSE);
 
-	mbox_hdr = mbox_from_create("dovecot.deliver", ioloop_time);
+	envelope_sender = address_sanitize(envelope_sender);
+	mbox_hdr = mbox_from_create(envelope_sender, ioloop_time);
 
 	input_list[0] = i_stream_create_from_data(default_pool, mbox_hdr,
 						  strlen(mbox_hdr));
@@ -347,6 +370,7 @@
 int main(int argc, char *argv[])
 {
 	const char *config_path = DEFAULT_CONFIG_FILE;
+	const char *envelope_sender = DEFAULT_ENVELOPE_SENDER;
 	const char *mailbox = "INBOX";
 	const char *auth_socket, *env_tz;
 	const char *home, *destination, *user, *mail_env, *value;
@@ -408,6 +432,14 @@
 					       "Missing mailbox argument");
 			}
 			mailbox = argv[i];
+		} else if (strcmp(argv[i], "-f") == 0) {
+			/* envelope sender address */
+			i++;
+			if (i == argc) {
+				i_fatal_status(EX_USAGE,
+					       "Missing envleope argument");
+			}
+			envelope_sender = argv[i];
 		} else {
 			print_help();
 			i_fatal_status(EX_USAGE,
@@ -516,7 +548,7 @@
 
 	mbox_storage = mail_storage_create("mbox", "/tmp", destination, 0,
 					   MAIL_STORAGE_LOCK_FCNTL);
-	input = create_mbox_stream(0);
+	input = create_mbox_stream(0, envelope_sender);
 	box = mailbox_open(mbox_storage, "Dovecot Delivery Mail", input,
 			   MAILBOX_OPEN_NO_INDEX_FILES |
 			   MAILBOX_OPEN_MBOX_ONE_MSG_ONLY);



More information about the dovecot-cvs mailing list