www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - E-mail attachment with scrambled text.

reply vino.B <bheeman.vino hotmail.com> writes:
Hi All,

   Request your help, i have a D code which generates a log file 
with below text, in Linux, when i send this log file(text file) 
as an mail attachment the text in the attachment are scrambled so 
request your help on this.

Tried the below Options (no luck):
Content-Type: text/plain
Content-Transfer-Encoding: base64

Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

Output in Linux
************Server Details******************
Server Name : 1XXXX     IP: 1XXXXXX
Server Name : 2XXXX     IP: 2XXXXXX
Server Name : 3XXXX     IP: 3XXXXXX
********************************************

The output in Windows(Email attachment) all are in single line

************Server Details******************Server Name : 1XXXX   
   IP: 1XXXXXXServer Name : 2XXXX     IP: 2XXXXXX Server Name : 
3XXXX     IP: 3XXXXXX
********************************************


From,
Vino.B
Jun 28 2018
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Thursday, 28 June 2018 at 11:46:31 UTC, vino.B wrote:
 Output in Linux
 ************Server Details******************
 Server Name : 1XXXX     IP: 1XXXXXX
 Server Name : 2XXXX     IP: 2XXXXXX
 Server Name : 3XXXX     IP: 3XXXXXX
 ********************************************

 The output in Windows(Email attachment) all are in single line

 ************Server Details******************Server Name : 1XXXX
   IP: 1XXXXXXServer Name : 2XXXX     IP: 2XXXXXX Server Name : 
 3XXXX     IP: 3XXXXXX
 ********************************************
Looks to be an issue with newlines. In linux, a newline is simply \n. In Windows it's \r\n, and some Windows programs get confused when they just see a \n, notably notepad. Notepad++ and basically any other editor will handle Unix newlines correctly. -- Simen
Jun 28 2018
parent reply vino.B <bheeman.vino hotmail.com> writes:
On Thursday, 28 June 2018 at 12:36:11 UTC, Simen Kjærås wrote:
 On Thursday, 28 June 2018 at 11:46:31 UTC, vino.B wrote:
 Output in Linux
 ************Server Details******************
 Server Name : 1XXXX     IP: 1XXXXXX
 Server Name : 2XXXX     IP: 2XXXXXX
 Server Name : 3XXXX     IP: 3XXXXXX
 ********************************************

 The output in Windows(Email attachment) all are in single line

 ************Server Details******************Server Name : 1XXXX
   IP: 1XXXXXXServer Name : 2XXXX     IP: 2XXXXXX Server Name : 
 3XXXX     IP: 3XXXXXX
 ********************************************
Looks to be an issue with newlines. In linux, a newline is simply \n. In Windows it's \r\n, and some Windows programs get confused when they just see a \n, notably notepad. Notepad++ and basically any other editor will handle Unix newlines correctly. -- Simen
Hi Simen, Thank you very much, after replacing all the '\n' with '\r\n' it resolved 99% of the formatting issue expect for the below function, can you help me on the same. auto getAvailableDiskSpace(Array!string UtilDrive, File logF) { auto result = ["/usr/bin/df", "-h", UtilDrive, "--output=target,size,used,avail,pcent"].execute; enforce(result.status == 0); logF.writeln(result.output); } The output of the above code is as below(Single line) Mounted on Size Used Avail Use%/backup 3.0T 2.6T 393G 87% From, Vino.B
Jun 28 2018
parent Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Thursday, 28 June 2018 at 14:42:36 UTC, vino.B wrote:
  Thank you very much, after replacing all the '\n' with '\r\n' 
 it resolved 99% of the formatting issue expect for the below 
 function, can you help me on the same.

 auto getAvailableDiskSpace(Array!string UtilDrive, File logF) {
 auto result = ["/usr/bin/df", "-h", UtilDrive, 
 "--output=target,size,used,avail,pcent"].execute;
 enforce(result.status == 0);
 logF.writeln(result.output);

 }
std.array.replace[0] is your friend: auto getAvailableDiskSpace(Array!string UtilDrive, File logF) { import std.array : replace; auto result = ["/usr/bin/df", "-h", UtilDrive, "--output=target,size,used,avail,pcent"].execute; enforce(result.status == 0); logF.writeln(result.output.replace("\n", "\r\n")); } -- Simen [0]: https://dlang.org/phobos/std_array.html#.replace
Jun 29 2018