[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[coldsync-hackers] send-mail conduit



I fixed the send-mail conduit so that headers are properly escaped. It
seems to work fine this way.

  Sam

PS/ is this list appropriate for sending patches or is there another address?
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam

Index: upstream.2_2_3_20011030.1/conduits/send-mail
--- upstream.2_2_3_20011030.1/conduits/send-mail Mon, 12 Nov 2001 09:16:21 +0100 sam (coldsync/b/1_send-mail 1.1 755)
+++ Sam.2/conduits/send-mail Mon, 12 Nov 2001 14:19:34 +0100 sam (coldsync/b/1_send-mail 1.2 755)
@@ -24,6 +24,16 @@
 
 my $VERSION = (qw( $Revision$ ))[1];	# Conduit version
 
+# Print a valid mail header
+sub print_header {
+  my ($header_name, $header_content) = @_;
+
+  if ($header_content ne "") {
+    $header_content =~ s/\n(\S)/\n\t$1/mg;
+    print SENDMAIL "$header_name: $header_content\n";
+  }
+}
+
 StartConduit("dump");
 
 $Text::Wrap::columns = $HEADERS{Wrap};
@@ -50,22 +60,17 @@
 		die "502 Can't run $HEADERS{Sendmail}: $!\n";
 	select SENDMAIL;
 
-	# XXX - Some of these headers are bogus. In particular, a "to"
-	# field that contains "arensb,\narnie" will not result in an
-	# RFC822-compliant header (the \n should be followed by
-	# whitespace).
-	print "From: $whoami\n";
-	print "To: ", $record->{to}, "\n" if $record->{to} ne "";
-	print "Cc: ", $record->{cc}, "\n" if $record->{cc} ne "";
-	print "Bcc: ", $record->{bcc}, "\n"
-		if $record->{bcc} ne "";
-	print "Reply-To: ", $record->{reply_to}, "\n"
-		if $record->{reply_to} ne "";
-	print "X-Sent-To: ", $record->{sent_to}, "\n"
-		if $record->{sent_to} ne "";
-	print "X-Mailer: $HEADERS{Daemon} $HEADERS{Version}/send-mail conduit $VERSION\n";
-	print "Subject: ", $record->{subject}, "\n"
-		if $record->{subject} ne "";
+	# Print header fields so that they conform to RFC822 (a continuation
+	# line must start with a whitespace or tab character).
+	print_header ("From", $whoami);
+	print_header ("To", $record->{"to"});
+	print_header ("Cc", $record->{"cc"});
+	print_header ("Bcc", $record->{bcc});
+	print_header ("Reply-To", $record->{reply_to});
+	print_header ("X-Sent-To", $record->{send_to});
+	print_header ("X-Mailer",
+	   "$HEADERS{Daemon} $HEADERS{Version}/send-mail conduit $VERSION");
+	print_header ("Subject", $record->{subject});
 
 	my $body = $record->{body};