[Gnucash-changes] r13675 - meta/hooks - Handle the pwent/RFC2704 processing ourself because sendmail wont.

Derek Atkins warlord at cvs.gnucash.org
Mon Mar 20 17:05:22 EST 2006


Author: warlord
Date: 2006-03-20 17:05:22 -0500 (Mon, 20 Mar 2006)
New Revision: 13675
Trac: http://svn.gnucash.org/trac/changeset/13675

Modified:
   meta/hooks/commit-email.pl
Log:
Handle the pwent/RFC2704 processing ourself because sendmail wont.
This way Andreas Köhler's name will appear properly in commit messages.


Modified: meta/hooks/commit-email.pl
===================================================================
--- meta/hooks/commit-email.pl	2006-03-20 02:08:00 UTC (rev 13674)
+++ meta/hooks/commit-email.pl	2006-03-20 22:05:22 UTC (rev 13675)
@@ -37,6 +37,7 @@
 use strict;
 use Carp;
 use MIME::QuotedPrint;
+use User::pwent;
 
 ######################################################################
 # Configuration section.
@@ -445,20 +446,35 @@
 	$subject = "$subject - $logmsg";
       }
     my $mail_from = $author;
+    my $sender = $mail_from;
+    my $fullname = get_fullname($author);
+    if ($fullname) {
+	$mail_from = "\"$fullname\" <$author>";
+    }
 
     if ($from_address =~ /\w/)
       {
-        $mail_from = $from_address;
+        $mail_from = $sender = $from_address;
+	$fullname = get_fullname($mail_from);
+	if ($fullname) {
+	    $mail_from = "\"$fullname\" <$from_address>";
+	}
       }
     elsif ($hostname =~ /\w/)
       {
-        $mail_from = "$mail_from\@$hostname";
+        $sender = "$mail_from\@$hostname";
+	$fullname = get_fullname($mail_from);
+	if ($fullname) {
+	    $mail_from = "\"$fullname\" <$sender>";
+	} else {
+	    $mail_from = $sender;
+	}
       }
 
     my @head;
     push(@head, "To: $to\n");
-    my $mail_from_str = header_encode($mail_from);
-    push(@head, "From: $mail_from_str\n");
+    $mail_from = header_encode($mail_from);
+    push(@head, "From: $mail_from\n");
     $subject = header_encode($subject);
     push(@head, "Subject: $subject\n");
     push(@head, "Reply-to: $reply_to\n") if $reply_to;
@@ -496,7 +512,7 @@
     if ($sendmail =~ /\w/ and @email_addresses)
       {
         # Open a pipe to sendmail.
-        my $command = "$sendmail -f$mail_from $userlist";
+        my $command = "$sendmail -f$sender $userlist";
         if (open(SENDMAIL, "| $command"))
           {
             print SENDMAIL @head, @body;
@@ -664,3 +680,15 @@
     }
     return $header;
 }
+
+sub get_fullname
+{
+    my ($username) = @_;
+
+    my $pw = getpwnam($username);
+    if ($pw) {
+	my ($name) = split (/\s*,\s*/, $pw->gecos);
+	return $name;
+    }
+    return undef;
+}



More information about the gnucash-changes mailing list