Bug 66761 - Other: Macro controlled Python Mailmerge broken
Summary: Other: Macro controlled Python Mailmerge broken
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.0.0.3 release
Hardware: Other Windows (All)
: high critical
Assignee: Caolán McNamara
URL:
Whiteboard: BSA target:4.2.0 target:4.0.5 target:...
Keywords: regression
Depends on:
Blocks:
 
Reported: 2013-07-10 09:48 UTC by Fernand
Modified: 2013-07-15 14:39 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fernand 2013-07-10 09:48:04 UTC
sinds 4.0 sending emails using the mailmerge.py is no longer working

Steps to reproduce:
the code below worked fine until 3.6 , using the cliboard to email the content of thiscomponent 



Sub Main

oMailProvider = CreateUNOService("com.sun.star.mail.MailServiceProvider")
oCont = CreateUNOListener("CurCont_","com.sun.star.uno.XCurrentContext")
oAuth = CreateUNOListener("Authent_","com.sun.star.mail.XAuthenticator")
'xCopyToClipboard("tekst als body")
copydoccontentToClipboard
oClip = CreateUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")

oMailServiceObj = com.sun.star.mail.MailMessage
rem http://api.openoffice.org/docs/common/ref/com/sun/star/mail/MailMessage.html
rem Use the contents of the clipboard as the content of the email
xMailServer = oMailProvider.Create("com.sun.star.mail.SMTP")
xMailServer.Connect(oCont,oAuth)
'msgbox xMailServer.isConnected
'sendarray() = split("sos@pmg.be , baj@pmg.be")
oMail = oMailServiceObj.create("sos@pmg.be" , "sos@pmg.be", "Verschenen berichten van SOUDAL",oClip.getContents()) 
'for i = 1 to ubound(sendarray())
'omail.addattachment(sendarray(i))
'next i
xMailServer.SendMailMessage(oMail)
xMailServer.Disconnect()

End Sub

Function CurCont_GetValueByName(s) as Any
    Select Case s
        Case "ServerName"
            CurCont_GetValueByName = "yourmailserver"
        Case "Port"
            CurCont_GetValueByName = 25
        Case "ConnectionType"
            CurCont_GetValueByName = "Insecure"
    End Select
End Function

Function Authent_GetUserName() as Any
    Authent_GetUserName = "youremailaccount"
End Function

Function Authent_GetPassword()
    Authent_GetPassword = "yourpasswordt"
End Function

Sub xCopyToClipboard(mytext as string)
dim document   as object
dim dispatcher as object
dim oDoc, oVC, Mark, var
oVC = ThisComponent.CurrentController.getViewCursor

If Not isEmpty(oVC.TextTable) then  ' Cursor is in een Tabel
otext = oVC.texttable.getcellbyname(oVC.cell.cellname,true).text
textincell = oText.string
oText.string = ""
otext.insertstring(oVC,mytext,false)
oVC.gotostart(true)
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:Copy", "", 0, Array())
otext.string = textincell ' oude text terug zetten !
else
If Not isEmpty(oVC.TextFrame)then
oVC.String = mytext 
Mark = oVC.TextFrame.text.createTextCursorbyRange(oVC)
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:Copy", "", 0, Array())
'oVC.gotostart(true)
oVC.String = ""
else
'gewoon in de text
oVC.String = mytext
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:Copy", "", 0, Array())
oVC.String = ""
endif
endif

End sub

sub copydoccontentToClipboard
dim document   as object
dim dispatcher as object
dim oDoc, oVC, Mark, var
oVC = ThisComponent.CurrentController.getViewCursor
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:SelectAll", "", 0, Array())
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:SelectAll", "", 0, Array())
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:Copy", "", 0, Array())
end sub

              
Operating System: Windows 8
Version: 4.0.0.3 release
Last worked in: 3.6.6.2 release
Comment 1 Fernand 2013-07-10 09:57:02 UTC
the mailmerge.py was made by Caolan McNamara
Comment 2 Alex Thurgood 2013-07-11 11:06:49 UTC
Editing title to reflect report.
Comment 3 Alex Thurgood 2013-07-11 11:07:52 UTC
Fernand,

Some work has been done on mailmerge since 4.0 release. Could you try with a more recent version of LO ?


Alex
Comment 4 Alex Thurgood 2013-07-11 11:08:56 UTC
Adding Caolan to CC.
Comment 5 Alex Thurgood 2013-07-11 11:14:18 UTC
If I try and run your code in 
Version 4.0.3.3 (Build ID: 0eaa50a932c8f2199a615e1eb30f7ac74279539) 

from the Basic IDE via a new module in a Writer document, I get the following error :

Erreur d'exécution BASIC.
Une exception s'est produite : 
Type: com.sun.star.uno.RuntimeException
Message: <class 'socket.gaierror'>: (8, 'nodename nor servname provided, or not known'), traceback follows
  /Applications/LibreOffice.app/Contents/program/LibreOfficePython.framework/Versions/Current/lib/python3.3/socket.py:406 in function create_connection() [for res in getaddrinfo(host, port, 0, SOCK_STREAM):]
  /Applications/LibreOffice.app/Contents/program/LibreOfficePython.framework/Versions/Current/lib/python3.3/smtplib.py:288 in function _get_socket() [self.source_address)]
  /Applications/LibreOffice.app/Contents/program/LibreOfficePython.framework/Versions/Current/lib/python3.3/smtplib.py:317 in function connect() [self.sock = self._get_socket(host, port, self.timeout)]
  /Applications/LibreOffice.app/Contents/program/LibreOfficePython.framework/Versions/Current/lib/python3.3/smtplib.py:238 in function __init__() [(code, msg) = self.connect(host, port)]
  /Applications/LibreOffice.app/Contents/program/mailmerge.py:99 in function connect() [self.server = smtplib.SMTP(server, port,timeout=tout)]


How is this code supposed to be run ? From within a document or from the command line ?


Alex
Comment 6 Alex Thurgood 2013-07-11 11:20:34 UTC
And on Version: 4.2.0.0.alpha0+
Build ID: 0581c61c8b61041692befac101466190767e6597


OSX 10.8.4 my own master build

the same thing (running from Basic IDE) does absolutely nothing at all, not even an error message. I can click on the Compile/Execute buttons to my heart's content, but nothing happens.


Alex
Comment 7 Alex Thurgood 2013-07-11 11:25:33 UTC
My bad, I forgot that you need to put the cursor at the top of the code to get it to run.

On OSX 10.8.4 and LO 3.6.6, I get the same error mentioned previously at this line :

xMailServer.Connect(oCont,oAuth)


So this doesn't even work for me in that version of LO.


Alex
Comment 8 Alex Thurgood 2013-07-11 11:29:37 UTC
(In reply to comment #7)



And same error on master build 4.2.0.0 alpha

Alex
Comment 9 Alex Thurgood 2013-07-11 11:32:27 UTC
(In reply to comment #8)
> (In reply to comment #7)
> 
> 
> 
> And same error on master build 4.2.0.0 alpha
> 
> Alex

I guess I must be doing something wrong, because running this macro on LO 3.3.4 OSX 10.8.4 gives the same error.


Alex
Comment 10 Fernand 2013-07-11 14:35:39 UTC
Alex,

for running the code open Tehe basic IDE
open a writerdoc with some text
replace the "yourservername" , "youremailaccount" and "yourpassword" to values corresponding to your emailserver settings.
oMailServiceObj.create("sos@pmg.be" , "sos@pmg.be", "Verschenen berichten van SOUDAL",oClip.getContents())
change also the values "sos@pmg.be" = my emailadres as recipient Adres
the second "sos@pmg.be" = the SendFrom adress
"Verschenen berichten van SOUDAL" = the subject
run the code
the text from the Writerdoc will been copied in the mailbody and the email will been send to "sos@pmg.be"
with 3.6 is sould work

Greetz
Comment 11 Petr Mladek 2013-07-11 15:17:28 UTC
It works for me with 4.1.0.2 Linux x86_64 build on SLED11-SP3.

I see the following error with 4.0.4.2 Linux x86_64 build:

--- cut ---
BASIC runtime error.
An exception occurred 
Type: com.sun.star.uno.RuntimeException
Message: <class 'AttributeError'>: 'ByteSequence' object has no attribute 'encode', traceback follows
  /opt/libreoffice4.0/program/mailmerge.py:184 in function sendMailMessage() [textbody = textbody.encode('utf-8')]
--- cut ---

I wonder if it triggers any bell.
Comment 12 Fernand 2013-07-12 06:43:36 UTC
Yep,

same error on windows

in 3.3 there was no encoding off the Body so only pure ASCI was well handled
for non ASCI characters French assents etc... we need a encoding to UTF-8
Later the "Body.encode" was introduced in the code
When using the clipboard as content then do we have a 'ByteSequence'  ?
and the error 'ByteSequence' object has no attribute 'encode'means that a ByteSequence must not been encoded or encoded in a different way ?
Comment 13 Petr Mladek 2013-07-12 13:47:10 UTC
It is strange. I get the same error, mentioned in comment #11, with LO 4.1.0.2 on Windows. I get the error also with my test build from the libreoffice-4-1-0 branch on Linux x86_64 system. But it works (sends a mail) with the official 4.1.0.2.0 build on the same Linux system.

I tried to do some trivial debugging with moving python scripts between the builds but it did not help. It needs some deeper debugging by people that are more familiar with python.

We need to look at it but this bug does not affect normal users => it should not block the release with many other fixes and improvements => reducing severity a bit.
Comment 14 Commit Notification 2013-07-13 15:08:11 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=c4aa13c931da11164835a7aafbfd7e44bd5714ca

Resolves: fdo#66761 Macro controlled Python Mailmerge broken



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 15 Commit Notification 2013-07-13 17:25:16 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=955b20d81affb9082f97e0726625c40ce9f38866&h=libreoffice-4-0

Resolves: fdo#66761 Macro controlled Python Mailmerge broken


It will be available in LibreOffice 4.0.5.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 16 Commit Notification 2013-07-13 17:34:23 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-1":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=820fe067c0ede36f357fb214d0298e3caaff512f&h=libreoffice-4-1

Resolves: fdo#66761 Macro controlled Python Mailmerge broken


It will be available in LibreOffice 4.1.1.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 17 Commit Notification 2013-07-14 13:10:01 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=f460556bfa6bd55df3cd4b2288524d63db284d7e

Related: fdo#66761 we want the bytes, not a str representation of them



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 18 Commit Notification 2013-07-15 09:35:29 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=24078e3501042e8693ef1f9d3edebbc47e37ce12

Related: fdo#66761 the double-encoding bug appears gone in python 3.3.2



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 19 Commit Notification 2013-07-15 10:59:55 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-1":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=c71f67198cd6fc98f77289c4f0276a45d19700d8&h=libreoffice-4-1

Related: fdo#66761 the double-encoding bug appears gone in python 3.3.2


It will be available in LibreOffice 4.1.1.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 20 Commit Notification 2013-07-15 11:37:37 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=aab42944ad90e86ac43dedc7e11be8eb2019d833&h=libreoffice-4-0

Related: fdo#66761 the double-encoding bug appears gone in python 3.3.2


It will be available in LibreOffice 4.0.5.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 21 Commit Notification 2013-07-15 14:35:35 UTC
Caolan McNamara committed a patch related to this issue.
It has been pushed to "libreoffice-4-1-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=6a5ba90664634b288296c4e8eebc4cd6eabe6105&h=libreoffice-4-1-0

Resolves: fdo#66761 Macro controlled Python Mailmerge broken


It will be available already in LibreOffice 4.1.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 22 Caolán McNamara 2013-07-15 14:39:15 UTC
bit of a cluster of problems, immediate one is pretty straight forward, but got caught in a maze of similar but different python versions with/without bugs and workarounds.