Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Losing eol character using MIME::Lite

by cbeckley (Curate)
on Dec 08, 2017 at 17:26 UTC ( #1205191=perlquestion: print w/replies, xml ) Need Help??

cbeckley has asked for the wisdom of the Perl Monks concerning the following question:

Good Morning!

I have a small issue that I told myself I was going to ignore because the script works just fine ... but here we are.

The script monitors replication between two databases by updating a string field on the source with a timestamp, waiting a bit, retrieving the value from the target, and sending an email if they're not the same.

None of which matters because that stuff all works. And the part that doesn't work is purely cosmetic, but it's bugging me.

I've included a runnable stripped down sample script below, but the crux of the matter is this:

$source_heart_beat_timestamp = "20171207_113255"; $target_heart_beat_timestamp = "bar"; $output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_tim +estamp . "\n"; $output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timest +amp";

When  $source_heart_beat_timestamp contains something that looks like a timestamp, the trailing eol gets eaten, but only in the email body. It works fine with  say.
When  $source_heart_beat_timestamp contains "foo", the trailing eol is displayed properly both on stdout and in the email.

So, when  $source_heart_beat_timestamp contains "20171207_113255"
stdout looks like:

local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeStamp: bar

but the email body looks like:

local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeSta +mp: bar

However, when  $source_heart_beat_timestamp contains "foo"
both stdout and the email body look like:

local_do_mail: Source Heart Beat TimeStamp: foo Target Heart Beat TimeStamp: bar

Who's eating the eol?
At this point I'm willing to blame the dog, but if anybody could point me toward a more likely suspect, I would greatly appreciate it.
As would the dog.

Thanks,
cbeckley

Here's the whole script:

#!/usr/bin/perl use strict; use warnings; use v5.16; use MIME::Lite; my $source_heart_beat_timestamp = ''; my $target_heart_beat_timestamp = ''; sub local_do_mail { my ($msg_body) = @_; my $msg = MIME::Lite->new( From => 'cloudops@foo.com', To => 'cbeckley@foo.com', Subject => 'testing missing eol', Data => $msg_body ); $msg->send; } # # The mail output here includes the \n after the source_heartbeat # $source_heart_beat_timestamp = "foo"; $target_heart_beat_timestamp = "bar"; my $output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_ +timestamp . "\n"; $output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timest +amp"; say "local_do_mail:\n$output_msg"; local_do_mail("local_do_mail:\n$output_msg"); # # The mail output here does not include the \n after the source_heartb +eat # $source_heart_beat_timestamp = "20171207_113255"; $target_heart_beat_timestamp = "bar"; $output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_tim +estamp . "\n"; $output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timest +amp"; say "local_do_mail:\n$output_msg"; local_do_mail("local_do_mail:\n$output_msg");

And here are the outputs on stdout and in the emails, respectively:

Stdout:

local_do_mail: Source Heart Beat TimeStamp: foo Target Heart Beat TimeStamp: bar local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeStamp: bar

And the bodies of the two emails:

local_do_mail: Source Heart Beat TimeStamp: foo Target Heart Beat TimeStamp: bar
local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeSta +mp: bar

Replies are listed 'Best First'.
Re: Losing eol character using MIME::Lite
by marto (Archbishop) on Dec 09, 2017 at 10:14 UTC

    Is the client Microsoft outlook? If so I have seen similar problems is modern versions, for example. At work I've eve seen it display a message stating that lines had been stripped, with a 'click here to view original' option, somewhere in that awful mess of a UI they now have. Most of our emails are sent from perl on Solaris via MIME::Lite.

      Yes, it is Outlook, and Outlook is the culprit.

      Is there a MIME type that will instruct Outlook not to play games with the content?

      Thanks,
      cbeckley

        Yes, I have had the same problem with Outlook deciding to remove EOL characters. There may be an easier or better solution (and I would be interested to know), but we ended up specifying HTML content. And that works (even though the Outlook HTML renderer is not exactly the best).
Re: Losing eol character using MIME::Lite
by Anonymous Monk on Dec 09, 2017 at 03:49 UTC

    Hi

    Who's eating the eol? At this point I'm willing to blame the dog, but if anybody could point me toward a more likely suspect, I would greatly appreciate it. As would the dog.

    Start with Basic debugging checklist

    Also don't write your program in between subroutine declarations

    As you can see no newlines are missing

    Count the \n there are 2 in both messages

    "local_do_mail:\nSource Heart Beat TimeStamp: foo\nTarget Heart Beat T +imeStamp: bar" "local_do_mail:\nSource Heart Beat TimeStamp: 20171207_113255\nTarget +Heart Beat TimeStamp: bar"

    So who is to blame? The destination displaying the email body.

      Thand you for this:  use Data::Dump qw/ dd /;
      I didn't know about dd.

      You and Marto are correct, the problem is in the destination.
      That had not occurred to me; I thought I was missing some nuance of MIME or string syntax.

      Thank you.

      Thanks,
      cbeckley

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1205191]
Approved by johngg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2020-07-04 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?