Closed Bug 1491683 Opened 7 years ago Closed 6 years ago

Thunderbird doesn't attach files when called using NSSharingService on macOS

Categories

(Thunderbird :: Message Compose Window, defect)

52 Branch
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: edpostvak, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15 Steps to reproduce: I am an App developer for macOS and sell my Apps in the App Store. In my App there is the possibility to send an e-mail which includes a PDF invoice. The only way to call an external mail application is by using NSSharingService (Sand Box, so it's not possible to just run another application). Calling NSSharingService, with Apple Mail everything works fine. The subject, to-address, body and attachments are populated automatically. With Thunderbird the subject, to-address and body are populated, but the attachments don't appear. Here is a link to the issue on StackOverflow: https://stackoverflow.com/questions/50674919/how-to-attach-files-using-nssharingservice . Several people have the exact same problem. I'm using Thunderbird 52.9.1 (64-bits) on macOS 10.13.6 , but the problem was always there, also on older versions of both Thunderbird and macOS. If you don't know how to reproduce the problem, I can send you a small App that will perform the call to NSSharingService, so you can easily test the issue. Actual results: Thunderbird opens the mail compose window, automatically populates the subject, to-address and the body, but fails to automatically attach the file. Expected results: Thunderbird should have opened the mail compose window, auto-populating subject, to-address and body, and also automatically attach the specified file(s).
Does it also happen with version 60? http://getthunderbird.com/
Flags: needinfo?(edpostvak)
I didn't know about version 60, but I downloaded it just now (on macOS 10.14). Retried, and, alas, the exact same behavior as 52.9.1 . The specified files are not attached.
Flags: needinfo?(edpostvak)
Looks a bit like bug 1335330, but the reporter had macOS 10.6 and they closed the bug. Any chance to reproduce a similar problem with Firefox? Like visit a website that let's you upload a file? Then file a bug for FF.
I personally don't think it's related. I am able to attach files manually in Thunderbird, also files from Samba shares. It goes wrong when I programmatically want a file to attach to a new message, using the NSSharingService. It will not appear in the new message, and I have no option but to attach it manually. If you want I can upload a very small App that will do very a very simple call to the NSSharingService. Then you'll see that with Apple Mail it works perfectly fine (files get attached automatically), and with Thunderbird the files just don't get attached.
Sorry, no Apple gear in the house, and we don't have a Mac developer in the team either. What is the NSSharingService and how does it attach files to messages? Sounds like something similar to MS' MAPI interface which is used to invoke message creation from Windows or Windows programs.
Yes, I think it compares to MS' MAPI interface. Here's an example code, in Apple's Swift language: // BEGIN CODE -------------------- guard let service: NSSharingService = NSSharingService(named: NSSharingServiceNameComposeEmail) else { myMessage("Can't open NSSharingService..."); return(false) } // initialize service service.recipients = ["test@domain.com"] // array of e-mail addresses service.delegate = rootAppDelegate service.subject = "This is the subject" // subject // Now add message body to shareItems array var shareItems = [Any]() shareItems.append(messageBody as Any) // Now add attachment to shareItems array let attachment = "/users/username/Documents/file_to_attach.txt" // string with attachment file name let u = URL(fileURLWithPath: attachment) // convert into URL shareItems.append(u as Any) // add to shareItems // now finally invoke NSSharingService to open mail client with populated mail, with an attachment service.perform(withItems: shareItems) // END CODE -------------------- I'm sorry to read you have no macOS developers in the team. Perhaps I'll take a look at the Thunderbird code myself some day, when I have time. Perhaps there is some sort of wrapper that runs Thunderbird with some parameters, and that's where things go wrong.. If I find something, I'll let you know..
By the way: When invoked from the terminal command line, this works fine: ./thunderbird -compose "to=test@gmail.com,subject=cool,body=WOW,attachment='file:///somefile.txt'" The file gets attached automatically..
I honestly didn't know that there's something similar to MAPI for Mac. Yes, staffing for Mac is very poor. Our theme person keeps Mac up-to-date, but there's practically no development going on. Recently we contracted someone working on Mac, but they're working in a different field. I've thought of asking him for help when he's done with his assigned task. There appears to be some code that supports NSSharing in the Mozilla platform, see: https://searchfox.org/comm-central/search?q=NSSharing&case=false&regexp=false&path= I've never looked at it but it might be more geared towards Firefox.
Thank you.. I'll have a look at the link you sent. Technically, the NSSharingService is a bit wider than just MAPI, as you can also use it to share stuff on Twitter and other platforms. See https://developer.apple.com/documentation/appkit/nssharingservice for the details.
Found this in an Apple Developer forum: https://forums.developer.apple.com/thread/60493 There is a chance this problem is "by design" by Apple. The NSSharingService only seems to work with Apple's own Mail client. All other clients don't work. I'll try and find an alternative solution, like building a wrapper/bridge that can be called from my App using an URL, and then the wrapper will try and open a new mail in Thunderbird. This works: ./thunderbird -compose "to=test@gmail.com,subject=cool,body=WOW,attachment='file:///somefile.txt'" However, it only works if there is no instance of Thunderbird active.. Is there an extra parameter I can add so the compose command is communicated to the active instance of Thunderbird?
Hmm, doesn't evoking the command simply open a compose window in the active instance anyway? That's what seems to happen on Windows. I'm not aware of any special switches, the regular ones are documented here: https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options Usually we use -no-remote to force a new instance and you want just the opposite.
Hmm.. On macOS it starts a new instance and then it opens a small window saying "Close Thunderbird - Another instance of Thunderbird is already opened. Only one instance of Thunderbird can be active at the same time." and an OK button. After clicking OK, it's closed, and no compose window is shown. I've tried it with ./thunderbird -compose and with ./thunderbird-bin -compose .
By the way, this is Thunderbird 52.9.1 (64 bit) on macOS High Sierra 10.13.6 .. I'll give it another try with version 60.
With Thunderbird 60.2.1 on macOS 10.14 it's exactly the same, alas.. In the terminal, after closing the window, it also shows: "###!!! [Parent][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost"
I think NSSharingService is a bit lazy, and only supports attachments with Apple's own Mail program. With all other mail clients, it just initiates a mailto: link and that doesn't support attachments. So I think I should complain with Apple, but, as the issue has been open for many years, this probably ain't gonna work. I think I'll create a small App (that can't be downloaded in the App Store, because then you're forced to use the Sandbox, and you can't call other Apps) that registers a tbmailto: URL handler. If such an URL is called it then calls Thunderbird through a ./thunderbird -compose call, including also the attachments.. All that I need though is for it work if Thunderbird is already active.. Best to open a new "Bug report" for that. Seems to only happen with macOS.
Josiah is a dev on Mac
Thanks! Perhaps Josiah can shed some new light on this.
I can take a look, although I don't write macOS apps. Will try investigating by the end of the week.
Thank you in advance!
Flags: needinfo?(jsbruner)

My apologies for this super delayed response.

So I did a bit of playing around. As previously discussed: NSSharingService will only support attachments in Apple's Mail.app. Other clients, including TB, Outlook, and Spark do not handle the attachments. This seems to be intentional, as NSSharingService does not seem to require (or provide a mechanism for) applications to handle particular events.

So the command-line method seems to be the only way for now.

Share Extensions (https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Share.html) might allow us to register a mechanism for sharing (Spark does for example), but I'm not sure if it can provide enough functionality.

In either case, our interaction with NSSharingService isn't the problem.

To that end, I going to close this ticket (feel free to reopen if anyone disagrees). I also agree with the end of comment 15: a new bug should be created w.r.t. our handling of the -compose argument.

Flags: needinfo?(jsbruner)
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.