LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-18-2009, 01:28 AM   #1
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Rep: Reputation: 40
No newlines when mailing linux files to Outlook account


Hi.


I'm running swatch to analyze syslog messages in real time, and all unhandled messages are store in a file. Every day a bash script sends this file to my outlook account.

The problem, however, is that very often (but not always it seems), the email is very messy since outlook doesn't recognize the newlines. In other words, whereas in the file on the linux server everything looks normal, the email doesn't have newlines.

This is the relevant lines from my bash script:
Code:
touch $MESSAGE_FILE

echo "An initial message" > $MESSAGE_FILE
cat $SWATCH_FILE >> $MESSAGE_FILE 
cat $MESSAGE_FILE | mailx -s "$MAIL_SUBJECT" my@address

rm -f $MESSAGE_FILE
Doen anyone have a clue as to why this is happening? I'm guessing it has something to do with LF and LF+CR, but I'm not sure.

(Just thought of one thing: I'm gonna try using the unix2dos command on the $MESSAGE_FILE before I mail it, and hopefully it helps.)
 
Old 08-18-2009, 01:41 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,390
Blog Entries: 52

Rep: Reputation: 359Reputation: 359Reputation: 359Reputation: 359
Quote:
I'm guessing it has something to do with LF and LF+CR, but I'm not sure.
Spot on - the Unix convention is LF only, whereas the Microsoft convention is to use LF+CR. The LF+CR was appropriate for text terminals, but in a file it is simpler to just use a single character (takes less space, easier to parse).

Quote:
I'm gonna try using the unix2dos command on the $MESSAGE_FILE before I mail it, and hopefully it helps.
Should do the trick.
 
Old 08-18-2009, 02:18 AM   #3
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by neonsignal View Post
Spot on - the Unix convention is LF only, whereas the Microsoft convention is to use LF+CR. The LF+CR was appropriate for text terminals, but in a file it is simpler to just use a single character (takes less space, easier to parse).



Should do the trick.
Thanks for the fast reply.


I added this command:
Code:
unix2dos $MESSAGE_FILE 2>/dev/null
..but still not successfull...

Any ideas?
 
Old 08-18-2009, 02:39 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,390
Blog Entries: 52

Rep: Reputation: 359Reputation: 359Reputation: 359Reputation: 359
You can use the hexdump package, ie 'hexdump -c $MESSAGE_FILE' to examine whether the file has the format you want.

If it does have CR-LF, then these are getting stripped out by Outlook. You may want to check if the Outlook settings (Options->Email) have been set to "remove extra line breaks in plain text messages" (if you have that option). If it is removing the extra line breaks, it will be idiosyncratic, and will depend on the length of the line (since it is trying to guess the paragraph breaks).

Also, is the content type of the email set to 'text/plain'?

Another option would be to use HTML formatting in the email, and force breaks using a HTML <BR> tag.

eg
Code:
echo '<html>' >messagefile
echo '<h1>initial message</h1>' >>messagefile
sed -e 's/$/<br>/' logfile >>messagefile
echo '</html>' >>messagefile
cat messagefile | mail -s 'log file' -a 'Content-type: text/html' recipient@mail.org

Last edited by neonsignal; 08-18-2009 at 03:04 AM.
 
Old 08-18-2009, 03:22 AM   #5
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by neonsignal View Post
If it does have CR-LF, then these are getting stripped out by Outlook. You may want to check if the Outlook settings (Options->Email) have been set to "remove extra line breaks in plain text messages" (if you have that option). If it is removing the extra line breaks, it will be idiosyncratic, and will depend on the length of the line (since it is trying to guess the paragraph breaks).
I did the hexdump thing, and found that there was "/r /n" (i.e. CR-LF if I understand correctly). Found that the Outlook option you mentioned was set, and after untoggling it everything works perferctly! Thank you very much!

But I don't understand why my mail, which now has the correct CR-LF format due to unix2dos, don't work when the above mention option is set. I mean, why isn't outlook parsing CR-LF mail correctly when this option is set? Of course, it _may_ be the case that the actual mail being sent is converted back to linux format, but I'm not sure how likely this is.

Quote:
Originally Posted by neonsignal View Post
Also, is the content type of the email set to 'text/plain'?
Looks like my mail and mailx doesn't support this "-a" option. Very strange. Are you using a particular version or something?
 
Old 08-18-2009, 03:41 AM   #6
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Buster (Fluxbox WM)
Posts: 1,390
Blog Entries: 52

Rep: Reputation: 359Reputation: 359Reputation: 359Reputation: 359
Quote:
Looks like my mail and mailx doesn't support this "-a" option. Very strange. Are you using a particular version or something?
Nothing special here, just standard Debian (Lenny). The '-a' option just adds a line to the mail headers, it can be anything. You can get the same effect by including the header line at the start of the message file instead.

Quote:
why isn't outlook parsing CR-LF mail correctly when this option is set?
Possibly Outlook is trying to be clever.

Some mail readers in the past could not cope with long lines. So many mail clients in the past used to insert line breaks, autowrapping the outgoing lines to a fixed length (eg 80 characters). However, this in turn caused problems for the recipient when viewing the email in a window that was narrower than the original line length (you'd get a sequence of long-short-long-short lines). So in Outlook, when you turn on the 'remove line breaks', I suspect it is guessing at where the paragraph breaks are, and removing the rest of the line breaks, so that it can reformat the email nicely. This doesn't work well for a log file, where a short line does not mean a paragraph break, and long lines should not be concatenated.

Last edited by neonsignal; 08-18-2009 at 03:43 AM.
 
Old 08-18-2009, 05:51 AM   #7
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by neonsignal View Post
Nothing special here, just standard Debian (Lenny). The '-a' option just adds a line to the mail headers, it can be anything. You can get the same effect by including the header line at the start of the message file instead.



Possibly Outlook is trying to be clever.

Some mail readers in the past could not cope with long lines. So many mail clients in the past used to insert line breaks, autowrapping the outgoing lines to a fixed length (eg 80 characters). However, this in turn caused problems for the recipient when viewing the email in a window that was narrower than the original line length (you'd get a sequence of long-short-long-short lines). So in Outlook, when you turn on the 'remove line breaks', I suspect it is guessing at where the paragraph breaks are, and removing the rest of the line breaks, so that it can reformat the email nicely. This doesn't work well for a log file, where a short line does not mean a paragraph break, and long lines should not be concatenated.
I see. Thansk for the help - everything works perferctly now.
 
Old 02-28-2014, 09:34 AM   #8
EricNicot
LQ Newbie
 
Registered: Feb 2014
Posts: 1

Rep: Reputation: Disabled
Workaround adding spaces

A workaround is to add 2 spaces at the beginning of each line

echo "An initial message" > $MESSAGE_FILE
cat $SWATCH_FILE >> $MESSAGE_FILE
cat $MESSAGE_FILE | sed 's/^/ /g' | mailx -s "$MAIL_SUBJECT" my@address
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wanna to add in newlines in begin and end of multiple files tiaratiara Linux - Newbie 8 03-18-2009 09:32 PM
Outlook pst files in linux wild_oscar Linux - Software 2 05-23-2007 01:31 PM
Setting Up news group in outlook express for fedoracore mailing list Stormbird General 0 08-22-2006 06:41 PM
Hotmail account from linux mail application like Outlook in windows mwj Linux - Newbie 5 10-01-2003 03:43 AM
cron mailing to my account plisken Linux - General 1 02-18-2002 05:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration