Skip Menu |

This queue is for tickets about the MIME-Lite CPAN distribution.

Report information
The Basics
Id: 2759
Status: resolved
Priority: 0/
Queue: MIME-Lite

People
Owner: Nobody in particular
Requestors: dom [...] semantico.com
Cc: MSCHOUT [...] cpan.org
AdminCc:

Bug Information
Severity: Important
Broken in: 3.01
Fixed in: (no value)

Attachments
0001-send_by_sendmail-set-sender-by-default-as-documen.patch



Subject: send() doesn't set sender with send_by_sendmail()
I've just noticed that send() calls send_by_sendmail('/usr/sbin/sendmail -t -oi -oem'). Nothing wrong with that, except that it defeats the SetSender logic in send_by_sendmail(), so all my emails are coming out as from nobody... For the moment, I've switched to explicity call send_by_sendmail() instead of send(), but it would be useful to have send() call send_by_sendmail() in such a fashion that it's able to do the SetSender stuff. Thanks, -Dom
Date: Mon, 9 Jun 2003 10:15:02 UT
To: bug-MIME-Lite [...] rt.cpan.org
Subject: Refused: [cpan #2759] send() doesn't set sender with send_by_sendmail()
CC: <nobody [...] fsck.com>, " via RT" <bug-MIME-Lite [...] rt.cpan.org>
From: eryq [...] zeegee.com
RT-Send-Cc:
Sorry, but my spam filter doesn't recognize you, so your message is being deleted and returned. If you are trying to get in touch with me, please forward this letter back, and give it the special subject line of: white rabbit This will guarantee that I receive your message, and I may choose to add you to my whitelist. Or not.
Download (untitled)
message/rfc822 2.4k
Return-Path: <nobody@fsck.com> Received: from mr01.mrf.mail.rcn.net (207.172.4.20 [207.172.4.20]) by ms02.mrf.mail.rcn.net (Mirapoint Messaging Server MOS 3.2.2-GA FastPath) with ESMTP id CHQ76277; Mon, 09 Jun 2003 06:03:40 -0400 (EDT) Received: from virtual.mrf.mail.rcn.net (virtual.mrf.mail.rcn.net [207.172.4.103]) by mr01.mrf.mail.rcn.net (Mirapoint Messaging Server MOS 3.2.2-GA) with ESMTP id CPR14508; Mon, 9 Jun 2003 06:03:38 -0400 (EDT) Received: from one.develooper.com ([64.81.84.115] helo=ran-out.mx.develooper.com) by virtual.mrf.mail.rcn.net with smtp (Exim 3.35 #4) id 19PJV4-0006uC-00 for eryq@zeegee.com; Mon, 09 Jun 2003 06:03:38 -0400 Received: (qmail 24996 invoked by uid 225); 9 Jun 2003 10:03:34 -0000 Delivered-To: ERYQ@cpan.org Received: (qmail 24991 invoked by uid 507); 9 Jun 2003 10:03:34 -0000 Received: from pallas.eruditorum.org (HELO pallas.eruditorum.org) (63.251.136.85) by one.develooper.com (qpsmtpd/0.26-dev) with SMTP; Mon, 09 Jun 2003 03:03:30 -0700 Received: by pallas.eruditorum.org (Postfix, from userid 65534) id 65A62111EE; Mon, 9 Jun 2003 06:03:24 -0400 (EDT) Subject: [cpan #2759] send() doesn't set sender with send_by_sendmail() From: " via RT" <bug-MIME-Lite@rt.cpan.org> Reply-To: bug-MIME-Lite@rt.cpan.org In-Reply-To: <rt-2759@cpan> Message-ID: <rt-2759-7846.2.02204527172945@cpan.org> Precedence: bulk X-RT-Loop-Prevention: cpan RT-Ticket: cpan #2759 Managed-by: RT 2.0.15 (http://bestpractical.com/rt/) RT-Originator: SEMANTICO@cpan.org To: "AdminCc of cpan Ticket #2759": ; Date: Mon, 9 Jun 2003 06:03:24 -0400 (EDT) X-SMTPD: qpsmtpd/0.26-dev, http://develooper.com/code/qpsmtpd/ X-Spam-Check-By: one.develooper.com X-Spam-Status: No, hits=2.1 required=7.0 tests=CARRIAGE_RETURNS,IN_REP_TO,SPAM_PHRASE_01_02,SUPERLONG_LINE,TO_HAS_SPACES,TO_MALFORMED version=2.44 This message about MIME-Lite was sent to you by SEMANTICO <SEMANTICO@cpan.org> via rt.cpan.org Full context and any attached attachments can be found at: <URL: https://rt.cpan.org/Ticket/Display.html?id=2759 > I've just noticed that send() calls send_by_sendmail('/usr/sbin/sendmail -t -oi -oem'). Nothing wrong with that, except that it defeats the SetSender logic in send_by_sendmail(), so all my emails are coming out as from nobody... For the moment, I've switched to explicity call send_by_sendmail() instead of send(), but it would be useful to have send() call send_by_sendmail() in such a fashion that it's able to do the SetSender stuff. Thanks, -Dom
From: demerphq [...] hotmail.com
[SEMANTICO - Mon Jun 9 06:03:23 2003]: Show quoted text
> I've just noticed that send() calls > send_by_sendmail('/usr/sbin/sendmail -t -oi -oem'). Nothing wrong > with that, except that it defeats the SetSender logic in > send_by_sendmail(), so all my emails are coming out as from > nobody... > > For the moment, I've switched to explicity call send_by_sendmail() > instead of send(), but it would be useful to have send() call > send_by_sendmail() in such a fashion that it's able to do the > SetSender stuff.
Hi, Sorry for the delay in getting to this, Ive been very busy. However I have to say that im a touch at a loss to understand exactly what is going wrong here. Can you provide me with a code snippet that causes the problem you mean so i can trace it through? Are you sure this wasnt a bug on your behalf? I dont see how it ends up using the command you describe if you have already set the From using send earlier. Ie, if you called MIME::Lite->send('sendmail',FromSender => 'me@myhost.com'); and then later $msg->send(); then it should be the same as calling $msg->send_by_sendmail(FromSender => 'me@myhost.com'); But I have to admit I dont have sendmail handy to test against, and as such without a code snippet that causes the error to work from its difficult for me to fix this. Cheers, Yves
This is copied from a debian bug report that I opened. As a result, some of the line numbers below may not match the source package, but they should be close enough that it doesn't matter. From the documentation: -- begin -- SetSender Unless this is explicitly given as false, we attempt to automatically set the -f argument to the first address that can be extracted from the "From:" field of the message (if there is one). What is the -f, and why do we use it? Suppose we did not use -f, and you gave an explicit "From:" field in your message: in this case, the sendmail "envelope" would indicate the real user your process was running under, as a way of preventing mail forgery. Using the -f switch causes the sender to be set in the envelope as well. -- end -- A simple test case: root@test:~# cat test.pl #!/usr/bin/perl -w use strict; use MIME::Lite; my $msg = MIME::Lite->new( From =>'foo@hrsmart.com', To =>'sallen@hrsmart.com', Subject =>'Helloooooo, nurse!', Data =>"How's it goin', eh?" ); $msg->send(); root@test:~# perl test.pl root@test:~# tail -3 /var/log/exim/mainlog 2006-09-11 10:30:04 1GMnjX-0007Br-00 <= root@hrsmart.com U=root P=local S=507 2006-09-11 10:30:04 1GMnjX-0007Br-00 => sallen@hrsmart.com R=lookuphost T=remote_smtp H=mail.hrsmart.com [xx.xx.xx.xx] 2006-09-11 10:30:04 1GMnjX-0007Br-00 Completed Here's the resulting message source: X-Real-To: sallen@hrsmart.com Return-Path: <root@hrsmart.com> Received: from test.hrsmart.com ([xx.xx.xx.xx] verified) by franklin.hrsmart.com (SMTP) with ESMTP id 2191773 for sallen@hrsmart.com; Mon, 11 Sep 2006 10:30:20 -0500 Received: from root by test.hrsmart.com with local (Exim 3.36 #1 (Debian)) id 1GMnjX-0007Br-00 for <sallen@hrsmart.com>; Mon, 11 Sep 2006 10:30:03 -0500 Content-Disposition: inline Content-Length: 19 Content-Transfer-Encoding: binary Content-Type: text/plain MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.72; B3.04; Q3.03) Date: Mon, 11 Sep 2006 15:30:02 UT From: foo@hrsmart.com To: sallen@hrsmart.com Subject: Helloooooo, nurse! Message-Id: <E1GMnjX-0007Br-00@test.hrsmart.com> How's it goin', eh? An alternate test case: root@test:~# cat test.pl #!/usr/bin/perl -w use strict; use MIME::Lite; my $msg = MIME::Lite->new( From =>'foo@hrsmart.com', To =>'sallen@hrsmart.com', Subject =>'Helloooooo, nurse!', Data =>"How's it goin', eh?" ); $msg->send_by_sendmail(); root@test:~# perl test.pl root@test:~# tail -3 /var/log/exim/mainlog 2006-09-11 10:36:50 1GMnq6-0007Cg-00 <= foo@hrsmart.com U=root P=local S=507 2006-09-11 10:36:50 1GMnq6-0007Cg-00 => sallen@hrsmart.com R=lookuphost T=remote_smtp H=mail.hrsmart.com [xx.xx.xx.xx] 2006-09-11 10:36:50 1GMnq6-0007Cg-00 Completed Message source: X-Real-To: sallen@hrsmart.com Return-Path: <foo@hrsmart.com> Received: from test.hrsmart.com ([xx.xx.xx.xx] verified) by franklin.hrsmart.com (SMTP) with ESMTP id 2191967 for sallen@hrsmart.com; Mon, 11 Sep 2006 10:37:06 -0500 Received: from root by test.hrsmart.com with local (Exim 3.36 #1 (Debian)) id 1GMnq6-0007Cg-00 for <sallen@hrsmart.com>; Mon, 11 Sep 2006 10:36:50 -0500 Content-Disposition: inline Content-Length: 19 Content-Transfer-Encoding: binary Content-Type: text/plain MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.72; B3.04; Q3.03) Date: Mon, 11 Sep 2006 15:36:50 UT From: foo@hrsmart.com To: sallen@hrsmart.com Subject: Helloooooo, nurse! Message-Id: <E1GMnq6-0007Cg-00@test.hrsmart.com> How's it goin', eh? Things to note: 1. The log lines in test #2 shows the message from foo, not root. 2. The Return-Path header in #2 shows the message from foo, not root. These are the effects of the SetSender flag. It is supposed to be active by default, per the documentation. The problem is a result of an inconsistency in send_by_sendmail, which I am filing an additional bug report about. send_by_sendmail has two "modes" of operation. In the first, if arguments are passed in, no further processing is done. A pipe is opened to sendmail, and the message is sent using that pipe. The sendmail instance is executed using only the arguments passed in to send_by_sendmail; no further processing is done. This means the SetSender flag is ignored. The *actual* problem causing this issue is because the send() function uses default arguments for send_by_sendmail, which triggers the inconsistent behaviour noted above. From the module source: 380 ### Our sending facilities: 381 my $Sender = "sendmail"; 382 my %SenderArgs = ( 383 "sendmail" => ["$SENDMAIL -t -oi -oem"], 384 "smtp" => [], 385 "sub" => [], 386 ); .... <snip> .... 2440 sub send { 2441 my $self = shift; 2442 2443 if (ref($self)) { ### instance method: 2444 my ($method, @args); 2445 if (@_) { ### args; use them just this once 2446 $method = 'send_by_' . shift; 2447 @args = @_; 2448 } 2449 else { ### no args; use defaults 2450 $method = "send_by_$Sender"; 2451 @args = @{$SenderArgs{$Sender} || []}; 2452 } 2453 $self->verify_data if $AUTO_VERIFY; ### prevents missing parts! 2454 return $self->$method(@args); 2455 } .... <snip> .... 2536 sub send_by_sendmail { 2537 my $self = shift; 2538 2539 if (@_ == 1) { ### Use the given command... 2540 my $sendmailcmd = shift @_; 2541 2542 ### Do it: 2543 open SENDMAIL, "|$sendmailcmd" or Carp::croak "open |$sendmailcmd: $!\n"; 2544 $self->print(\*SENDMAIL); 2545 close SENDMAIL; 2546 return (($? >> 8) ? undef : 1); 2547 } 2548 else { ### Build the command... 2549 my %p = @_; 2550 $p{Sendmail} ||= "/usr/lib/sendmail"; 2551 2552 ### Start with the command and basic args: 2553 my @cmd = ($p{Sendmail}, @{$p{BaseArgs} || ['-t', '-oi', '-oem']}); 2554 2555 ### See if we are forcibly setting the sender: 2556 $p{SetSender} = 1 if defined($p{FromSender}); 2557 2558 ### Add the -f argument, unless we're explicitly told NOT to: 2559 unless (exists($p{SetSender}) and !$p{SetSender}) { 2560 my $from = $p{FromSender} || ($self->get('From'))[0]; Suggested fixes: 1. Move the default argument construction to a separate function: sub build_sendmail_args { # do the work occurring in lines 2549 - 2965 } 2. Change Sender Args like so: 380 ### Our sending facilities: 381 my $Sender = "sendmail"; 382 my %SenderArgs = ( 383 "sendmail" => [ build_sendmail_args() ], 384 "smtp" => [], 385 "sub" => [], 386 ); 3. Modify sub send_by_sendmail to use build_sendmail_args (to avoid code duplication) 4. Modify the documentation: SetSender Unless this is explicitly given as false **or unless you override the arguments being passed to sendmail**, we attempt to automatically set the -f argument to the first address that can be extracted from the "From:" field of the message (if there is one).
Subject: Bug report linked in the Debian BTS
From: GWOLF [...] cpan.org
Hi, Just to let you know that we have this bug filed in the Debian BTS: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=387003
From: MARKSTOS [...] cpan.org
I tried upgrading to 3.01_05 to fix this, but I got errors referring to UNIVERSAL::isa(), which was added in the newer code. (Perl 5.8.0, FreeBSD 5.1). What worked for me instead was to be very explicit: send_by_sendmail( Sendmail => "/usr/sbin/sendmail", BaseArgs => ["-t", "-oi", "-oem"], FromSender => '...', ); This works with sendmail and qmail. (There didn't seem a problem with Qmail anyway, as it was picking up the Return-Path set, I believe. ).
There are two problems with the implementation of send_by_sendmail() that prevent it from adding -fsender to the command line args. The attached patch makes it do what the documentation says it should do. First problem is that the "else" section in send_by_sendmail() never gets called because send() passes an argument to it with the contents of $SenderArgs{sendmail}. I fixed by dropping the $SenderArgs{sendmail} array. send_by_sendmail() generates the exact same command anyway. That is, it automatically adds -t -oi -oem which is all the SenderArgs was doing anyway. We still need to keep the SenderArgs placeholder though so that the class method still works (MIME::Lite->send(sendmail => '/foo/sendmail -t -oi -oem -whatever')). The second problem is that the docs say that the default is to ADD -fsender, unless you explicity disable it. However, $p{SetSender} is never initialized in send_by_sendmail(), so the result is that it will never add the -fsender unless you explicitly ask it to do that, either by using FromSender, or passing SetSender => 1. Fix for this issue was obvious. Attached patch fixes both problems, and includes a test case for the class method.
From 167f761008248efa7f308649d66f23b1e3be2c1b Mon Sep 17 00:00:00 2001 From: Michael Schout <mschout@gkg.net> Date: Wed, 15 Jul 2009 22:27:41 -0500 Subject: [PATCH] send_by_sendmail(): set sender by default as documented --- lib/MIME/Lite.pm | 5 ++++- t/sendmail.t | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletions(-) create mode 100644 t/sendmail.t diff --git a/lib/MIME/Lite.pm b/lib/MIME/Lite.pm index 412dd80..1149fa0 100644 --- a/lib/MIME/Lite.pm +++ b/lib/MIME/Lite.pm @@ -401,7 +401,7 @@ if ( $^O =~ /win32|cygwin/i ) { ### Our sending facilities: my %SenderArgs = ( - sendmail => [$SENDMAIL ? "$SENDMAIL -t -oi -oem" : undef], + sendmail => [], smtp => [], sub => [], ); @@ -2698,6 +2698,9 @@ sub send_by_sendmail { ### Start with the command and basic args: my @cmd = ( $p{Sendmail}, @{ $p{BaseArgs} || [ '-t', '-oi', '-oem' ] } ); + # SetSender default is true + $p{SetSender} = 1 unless defined $p{SetSender}; + ### See if we are forcibly setting the sender: $p{SetSender} ||= defined( $p{FromSender} ); diff --git a/t/sendmail.t b/t/sendmail.t new file mode 100644 index 0000000..4bd4d8f --- /dev/null +++ b/t/sendmail.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use lib "lib", "t"; +use MIME::Lite; +use Test::More tests => 2; + +use_ok('MIME::Lite') or exit 1; + +# set up dummy sendmail args. +MIME::Lite->send('sendmail', '/foo/bar/sendmail -x -y -z'); + +# retrieve the settings. +my @prev = MIME::Lite->send(sendmail => '/foo/bar/sendmail'); + +is_deeply \@prev, ['sendmail', '/foo/bar/sendmail -x -y -z'], + 'sendmail args updated'; -- 1.6.0.4
From: sup2000 [...] hotmail.com
I'm having this same problem with MIME::Lite. A couple of patches have been offered. I'm chiming in for two reasons: a) A "Me Too" report, to help you gauge how many people this is affecting; and, b) Ask "What can I do to help?" I see a few different approaches have been offered up, and a patch has been offered. This problem has been outstanding for more than 8 years (egads!) it seems. Can I re-work one of the patches, or do something to help resolve this bug once and for all? Thanks! Scott
fixed in git -- rjbs