Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: problem with 'bare LF' in script

by powerhouse (Friar)
on Nov 12, 2008 at 07:40 UTC ( [id://723071]=note: print w/replies, xml ) Need Help??


in reply to Re: problem with 'bare LF' in script
in thread problem with 'bare LF' in script

Yes, I am using Mail::Sendmail and have been for quite a few years.

I have tried everything, including these things:
$__to =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__cc =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__bcc =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__from =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__subject =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__html_message =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__text_message =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__importance =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__xpriority =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__x_ms_priority =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $_mail_Message =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; # And this: $_mail_Message =~ s/\cJ\cM$/\r\n/eg; # Done this for each of the variables...
Still it does not work. I am thinking at this point, that it is the module, Mail::Sendmail, maybe it is doing something that is causing the errors. I have tried everything, even sending fake information with only one letter in each field and still we get that message.

Maybe it is time for me to find another module to send out the emails one at a time or a bunch at once.

thx,
Richard

Replies are listed 'Best First'.
Re^3: problem with 'bare LF' in script
by graff (Chancellor) on Nov 12, 2008 at 14:34 UTC
    You said:

    I have tried everything, including these things:
    $__to =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__cc =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; ...

    Um, 'scuse me, but in your OP code snippets, you had this:

    my %mail = ( "To" => "$__to", "Subject" => "$__subject", "Content-Type" => $__content_type, );
    And you didn't really show us where the values of those scalars are coming from. Which means that these hash elements might never have had any line termination characters of any kind (in which case your substitutions would do nothing at all), or if they did have CR and/or LF, you might be screwing things up by having any sort of line-termination characters at all in those header values (this seems more likely).

    You might want to try this (if you haven't already):

    for ( $__to, $__subject, $__content_type, ... ) { tr/\r\n/ /; s/\s+$//; } my %mail = ( "To" => $__to, "Subject" => $__subject, "Content-Type" => $__content_type, );
    That will tell you whether Mail::Sendmail does the right thing in terms of appending CRLF at the end of every header field. If those strings already have CR and/or LF in them, you are probably asking for trouble. Ideally, Mail::Sendmail would be smart enough to make sure that any header field value does not contain either CR or LF before the module itself appends CRLF to each header field for output. (Having spurious CR and/or LF scattered around in the header fields is a Bad Thing.)

    As for the message body, I'd be inclined to try something like this:

    my @message_lines = ( '', # blank line 'This is a multi-part message in MIME format.', '','', # a couple blank lines "------=$_random_boundary", ..., # i.e. one array element for every line of message content '','' # including a couple blanks at the end ); my $_mail_message = join( "\r\n", @message_lines );

    My apologies for giving bad advice earlier (adding "\r" to the header fields) -- I should have known better.

Re^3: problem with 'bare LF' in script
by almut (Canon) on Nov 12, 2008 at 12:54 UTC

    Interestingly, Mail::Sendmail seems to be doing it right, i.e. it declares my $CRLF = "\015\012";, and then uses this consistently as the line ending whenever needed. In other words, I suppose the problem lies elsewhere.

Re^3: problem with 'bare LF' in script
by blazar (Canon) on Nov 12, 2008 at 13:31 UTC
    $__to =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__cc =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__bcc =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__from =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__subject =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__html_message =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__text_message =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__importance =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__xpriority =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $__x_ms_priority =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg; $_mail_Message =~ s/(\r\n|\n\r|\r|\n)/\r\n/sg;

    I personally believe that if those substitutions are in fact all the same substitution, which seems to be the case -and would be most reasonable/probable- although I'm not sure due the alignment... then I should point out, on a totally OT basis wrt your actual problem, that you'd probably better do:

    s{ \n\r | \r | \n }{\r\n}gx for $__to, $__cc, $__bcc, $__from, $__subject, $__html_message, $__text_message, $__importance, $__xpriority, $__x_ms_priority, $_mail_Message;

    I also edited the regex to the point of:

    • removing a set of unnecessary capturing parens;
    • removing a pattern that would be replaced by itself;
    • improving readability with /x (incidentally, /s did nothing there...) and alternate delimiters.
    --
    If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://723071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-16 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found