Bug 135628 - SendSimpleMailMessage bodytext with new lines ends up as multiple recipients
Summary: SendSimpleMailMessage bodytext with new lines ends up as multiple recipients
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
5.2.7.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Stephan Bergmann
URL: https://bugzilla.mozilla.org/show_bug...
Whiteboard: target:25.8.0 target:25.2.0.0.beta2
Keywords: regression
Depends on:
Blocks: Macro Thunderbird-Interoperability
  Show dependency treegraph
 
Reported: 2020-08-11 07:57 UTC by Zeke
Modified: 2024-12-16 21:41 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Screenshot of output (81.88 KB, image/png)
2020-08-11 11:50 UTC, Zeke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zeke 2020-08-11 07:57:13 UTC
Description:
When sending email in a macro using sendSimpleMailMessage your bodytext can only have one row. If you have multiple rows divided with chr$(10) (new line) all rows ends up as additional recipents. 

LibreOffice 4.4.3.2 Base on Linux Mint 17.2 Mate 1.10.2 have not this problem.
LibreOffice 5.1.6.2 Base on Linux Mint 18.3 Mate 1.18.0 have not this problem.
LibreOffice 5.4.7.2 Base on Linux Mint 19.3 Cinnamon 4.4.8 have this problem.
LibreOffice 6.0.7.3 Base on Linux Mint 19.3 Cinnamon 4.4.8 have this problem.

Code:
	eMailer = createUnoService("com.sun.star.system.SimpleCommandMail")
	eMessage = eMailer.createSimpleMailMessage()
	eMessage.Recipient = eMailAdress
	eMessage.Subject=eSubject
	eMessage.Body=bodytext
	eMessage.Attachement=(Array(convertToUrl(filepath)))
	eMailer.sendSimpleMailMessage ( eMessage, _
	com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE )

System:

LO version 6.0.7.3

CPU threads: 8, OS: Linux 5.4, UI render: default, VCL: gtk3
Locale: sv-SE (en_US.UTF-8)
Linux Mint 19.3 Cinnamon 4.4.8

Steps to Reproduce:
1.Run the code above
2.
3.

Actual Results:
The mail client (tested thunderbird and evolution) opens up. If there is a chr$10 (new line) in the bodytext no rows are put into the bodytextfield. In the recipients field the original recipient is inserted and one recipient for every bodytext-row.

Expected Results:
Only one recipient and all rows of the bodytext in the bodytext field.


Reproducible: Always


User Profile Reset: No


OpenGL enabled: Yes

Additional Info:
-
Comment 1 Julien Nabet 2020-08-11 08:58:58 UTC
On pc Debian x86-64 with master sources updated today, I don't reproduce this.

I gave a try with:
Sub Main
	eMailer = createUnoService("com.sun.star.system.SimpleCommandMail")
	eMessage = eMailer.createSimpleMailMessage()
	eMessage.Recipient = "test@test.fr"
	eMessage.Subject="subject"
	eMessage.Body="body1"  + chr$(10) + "body2"  + chr$(10) + "body3"
	eMessage.Attachement=(Array(convertToUrl(filepath)))
	eMailer.sendSimpleMailMessage ( eMessage, _
	com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE )
End Sub

6.0 is an old branch.
Could you give a try to last stable LO version 6.4.5?
Comment 2 Zeke 2020-08-11 11:50:39 UTC
Created attachment 164153 [details]
Screenshot of output
Comment 3 Julien Nabet 2020-08-11 11:52:17 UTC
Thank you for your feedback.

Could you also attach the precise macro code you used?
Comment 4 Zeke 2020-08-11 11:58:30 UTC
The screenshot was with LO 6.4.5

code:

sub send_email(filepath as String, eMailAdress as String, yourOrderno as String)

	Dim eSubject as String
	Dim eMailer as Object
	Dim eMailClient as Object
	Dim eMessage as Object

	eSubject = "Delivery note your order " & yourOrderno

	eMailer = createUnoService("com.sun.star.system.SimpleCommandMail")
	eMessage = eMailer.createSimpleMailMessage()
	eMessage.Recipient = eMailAdress
	eMessage.Subject=eSubject
	eMessage.Body="Text1" & chr$(10) & "Text2" & chr$(10) & "Text3"
	eMessage.Attachement=(Array(convertToUrl(filepath)))
	eMailer.sendSimpleMailMessage ( eMessage, _
	com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE )

End sub
Comment 5 Julien Nabet 2020-08-11 12:07:32 UTC
I still don't reproduce the problem with your code (after having args of the function since LO complains I call the macro without args).
It seems I can't help here => uncc myself.
Since I don't have more questions, I'll put it back to UNCONFIRMED.
Comment 6 Zeke 2020-08-11 13:48:39 UTC
LO 5.1.6.2 seems to be the last version working.
LO 5.2.7.2 and onwards has this issue.
Comment 7 Zeke 2020-08-11 14:55:44 UTC
Tested with claws-mail instead of thunderbird and that was working with LO 6.4.5.

The issue seems to be between thunderbird and LO from version 5.2.7.2 and onwards.
Comment 8 Xisco Faulí 2021-02-09 15:12:12 UTC
Hello Zeke,
A new major release of LibreOffice is available since this bug was reported.
Could you please try to reproduce it with the latest version of LibreOffice
from https://www.libreoffice.org/download/libreoffice-fresh/ ?
I have set the bug's status to 'NEEDINFO'. Please change it back to
'UNCONFIRMED' if the bug is still present in the latest version.
Comment 9 Zeke 2021-02-15 07:06:21 UTC
New test with LO7.

New clean install of Linux Mint 20.1 Cinnamon.

sudo add-apt-repository ppa:libreoffice/ppa

Upgrade LO to latest fresh.

Assign an account to Thunderbird and test it so it can send email.

Run this code:

sub send_email(filepath as String, eMailAdress as String, yourOrderno as String)

Dim eSubject as String
Dim eMailer as Object
Dim eMailClient as Object
Dim eMessage as Object
Dim bodytxtstring as string

eSubject = "Delivery note your order " & yourOrderno
bodytxtstring="Please find delivery note attached" & chr$(10) & "as pdf." & chr$(10) & "Best Regards ..."

eMailer = createUnoService("com.sun.star.system.SimpleCommandMail")
eMessage = eMailer.createSimpleMailMessage()
eMessage.Recipient = eMailAdress
eMessage.Subject=eSubject
eMessage.Body=bodytxtstring
eMessage.Attachement=(Array(convertToUrl(filepath)))
eMailer.sendSimpleMailMessage ( eMessage, _
com.sun.star.system.SimpleMailClientFlags.NO_USER_INTERFACE )

end sub

Result in Thunderbird:

From: zxc@gmail.com
To: vbn@gmail.com
To: Please find delivery note attached
To: as pdf.
To: Best Regards ...
Subject: Delivery note your order 254456
Bodytext: (Nothing)

The bug seems to still be present in LO7.

Due to the bug we use the following code instead:

eSubject = "Delivery note " & deliveryID & " from your order no " & yourOrderno
shellstring="thunderbird -compose subject=" & eSubject & ",to=" & eMailAdress & ",message=/home/user1/Businessystem/txt/Deliveryconftxt,attachment='" & filepath & "'"
shell shellstring
Comment 10 pharmankur 2022-02-15 14:07:08 UTC
I am also having this EXACT problem with Libreoffice + Linux Mint + Thunderbird setting.

But it works well with evolution or Geary email client.


BTW Zeke, can you elaborate on your workaround code ?

--------------------
Due to the bug we use the following code instead:

eSubject = "Delivery note " & deliveryID & " from your order no " & yourOrderno
shellstring="thunderbird -compose subject=" & eSubject & ",to=" & eMailAdress & ",message=/home/user1/Businessystem/txt/Deliveryconftxt,attachment='" & filepath & "'"
shell shellstring
---------------------  

what exactly is this shellstring stuff ?
Comment 11 Zeke 2022-02-16 06:51:12 UTC
Explanation of the workaround we use as requested by Pharmankur:

eSubject = "Delivery note " & deliveryID & " from your order no " & yourOrderno
shellstring="thunderbird -compose subject=" & eSubject & ",to=" & eMailAdress & ",message=/home/user1/Businessystem/txt/Deliveryconftxt,attachment='" & filepath & "'"
shell shellstring

Shell execute a command at the cl (commandline)

Shellstring is a textstring with the command.

thunderbird starts thunderbird.
-compose tells thunderbird to initiate a mail to send.
subject= sets the mails subject.
to= sets the mails reciepent.
message= path to a textfil containing the bodytext of the mail.
attachment= path to a attachment file.
Comment 12 pharmankur 2022-02-16 10:06:23 UTC
Thank You Zeke for your quick response
That's a great workaround.
Thanks for sharing.
Comment 13 pharmankur 2022-02-16 12:52:00 UTC
Dear Zeke,
Based on your idea (of using shell script from libreoffice Macro) prepared a demo file.
It makes use of MUTT 

Details are here ---
https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=90100#p521622
Comment 14 dailyak77 2022-08-28 14:47:54 UTC Comment hidden (spam)
Comment 15 dailyak77 2023-01-05 04:09:47 UTC Comment hidden (spam)
Comment 16 Abdullah Sajid 2023-07-18 05:20:25 UTC Comment hidden (spam)
Comment 17 Zyen Malik 2023-09-29 11:49:49 UTC Comment hidden (spam)
Comment 18 Stéphane Guillou (stragu) 2023-10-18 19:37:44 UTC
Setting to new as per comment 10.
Version and regression keywords as per comment 6.
Comment 19 Stéphane Guillou (stragu) 2023-10-26 14:39:59 UTC
Is this the same issue as https://bugzilla.mozilla.org/show_bug.cgi?id=208230 ?
Which would make it "not our bug"?
Comment 20 pikashowpc 2023-11-14 07:03:47 UTC Comment hidden (spam)
Comment 21 pikashowpc 2023-11-14 07:09:41 UTC Comment hidden (spam)
Comment 22 Dolly Waelchi 2024-07-10 08:25:04 UTC
You must always have one recipient in the 'TO' field for the mass email to be sent. To accomplish this, just enter your own email address in that field.
Comment 23 Mike Kaganski 2024-12-16 06:41:04 UTC
(In reply to Stéphane Guillou (stragu) from comment #19)
> Is this the same issue as
> https://bugzilla.mozilla.org/show_bug.cgi?id=208230 ?

No. If it were, then the multiline text would appear as single-line with newlines converted to whitespace. Here, the additional lines appear as additional CC addresses.

(In reply to Julien Nabet from comment #1)
> On pc Debian x86-64 with master sources updated today, I don't reproduce
> this.

If it is reproducible - i.e., if the wrong CC addresses are added - would depend on the way mailer is configured in LibreOffice. Specifically, if the actual command executed in https://opengrok.libreoffice.org/xref/core/shell/source/unix/misc/senddoc.sh is xdg-email (when the mailer is not explicitly configured, or the command is entered manually), then the problem will be reproduced. If I specify 'thunderbird' explicitly, the problem is *not* reproducible that way (I don't have wrong CC addresses) - but the body is still not correct (this bit, unfortunately, is unclear in comment 1).

Having LibreOffice (24.8.3.2) and Thunderbird (115.16.0esr), both installed using apt on my Ubuntu (22.04.5 LTS), I don't have a body at all, even passing a single-line text to eMessage.Body; this is both then using 'xdg-email' and 'thunderbird' as configured mailer. In case of 'xdg-email', I see the *second* and following lines as CC addresses - but the first line is lost, anyway.

The shell script seems to have bis troubles; see e.g. bug 162632. Please note, that the issue is to debug the mentioned shell script, which is the actual thing executed when you use the SimpleCommandMail service. It is enough to edit it directly (in the LibreOffice installation directory) - adding some debug output could be the first step.
Comment 24 Mike Kaganski 2024-12-16 07:45:41 UTC
FTR: the shell script in the installed LibreOffice likely has no ".sh" extension: e.g., on my system, it's /usr/lib/libreoffice/program/senddoc
Comment 25 Mike Kaganski 2024-12-16 08:41:07 UTC
(In reply to Mike Kaganski from comment #23)
> If I specify 'thunderbird' explicitly, the problem is *not* reproducible
> that way (I don't have wrong CC addresses) - but the body is still not
> correct (this bit, unfortunately, is unclear in comment 1).
> 
> Having LibreOffice (24.8.3.2) and Thunderbird (115.16.0esr), both installed
> using apt on my Ubuntu (22.04.5 LTS), I don't have a body at all, even
> passing a single-line text to eMessage.Body; this is both then using
> 'xdg-email' and 'thunderbird' as configured mailer.

Please ignore the part about the *missing* body in my comment 23: it turned out, that it was caused by not configured account in Thunderbird (I only installed it to test, and hoped that it would work without configuring an account). Once an account was configured, the body appeared:

1. When using a command line like

> thunderbird -compose to='my@email.com',subject='A subject',body='Text1
> Text2
> Text3'

it worked fine. The body was three-line, as expected.

2. When using a command line like

> xdg-email 'mailto:my@email.com?body=Text1                                          > Text2
> Text3&subject=A%20subject'

the problem appeared, as explained in comment 0. The first line "Text1" was in the body, while "Text2" and "Text3" appeared as CC.

3. When using a command line like

> xdg-email 'mailto:my@email.com?&subject=A%20subject' --body 'Text1
Text2
Text3'

it worked fine again. The body was three-line, as expected.

It seems, that the correct fix would be to use the --body argument to xdg-email.
Comment 26 Mike Kaganski 2024-12-16 10:28:49 UTC
Also this works fine:

> xdg-email 'mailto:my@email.com?body=Text1%0AText2%0AText3&subject=A%20subject'

So the proper URL-encoding of the body is likely enough.
Comment 27 Commit Notification 2024-12-16 15:57:25 UTC
Stephan Bergmann committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6d1cddea8e4e19287891ab8fb7e3774ae9976ea1

tdf#135628 Let uri-encode encode newlines

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 28 Commit Notification 2024-12-16 21:41:55 UTC
Stephan Bergmann committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/cf4ab0e50087ae631b9f187b1b554da463474c27

tdf#135628 Let uri-encode encode newlines

It will be available in 25.2.0.0.beta2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.