How to attach files using NSSharingService - objective-c

I am preparing a Mail using NSSharingService. I mainly followed the advice given here: NSSharingService to send email and read email body
Effectively I am calling
[self.emailSharingService performWithItems:shareItems];
where shareItems is an NSArray containing one NSString object (the body) and several NSURL objects (the attachements)
With AppleMail the preparation of the mail works fine (e.g. body & attachments) but unfortunately the attachments are not added if I use another mail client (e.g. Thunderbird, Spark)
Does anyone know how I can achieve the addition of the attachments in other mail clients than AppleMail?

Related

Print original email when it is undelivered

I'm using MS Office 2016 Desktop App on Windows 10.
I didn't find any success searching online and also contacting MS Outlook Support to find that there is no easy way to achieve it except VBA script.
We send individual mail having an attachment, to a huge bulk of people. (I'm fine with this.)
I want when an email is not sent successfully (because of incorrect email address or other reason), to perform some action on the original email (not the undeliverable mail notice).
Possible action could be printing the mail and its attachments to some other email.
I want this as it is burdensome to print individual emails from around 1000s of emails daily.
MS Outlook rules don't provide the condition for 'when email undelivered' or similar. Can this be achieved with VBA script?
In theory - yes. Firstly, you need to make sure you get the actual NDR and the object type is ReportItem. That shouldn't be a problem if you are sending through Exchange, but if you are sending through POP3/SMTP account or if the NDR is delivered as a regular plain text message from the target server rather than your own Exchange Server, all bets are off.
The various report properties are stored in the recipient table of the NDR items. Unfortunately, ReportItem in OOM does not expose the Recipients collection like it does for MailItem. You can get NDR information from the Body property, but unfortunately OOM has a bug (left unfixed for a few years now) that causes ReportItem,Body to return meaningless garbled text. See Extract text string from undeliverable email body to Excel.
In most cases, you would be able to extract the message id of the original message (that caused in the NDR) from the PR_TRANSPORT_MESSAGE_HEADERS property (take a look at an NDR with OutlookSpy - I am its author - click IMessage button). You can access that property using ReportItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F"). You can then try to extract the In-Reply-To MIME header and use it to search for the original message in the Sent Items folder using Items.Find on the PR_INTERNET_MESSAGE_ID property (DASL name http://schemas.microsoft.com/mapi/proptag/0x1035001F). And here lies another problem - it is possible that the item in the Sent Items folder will not have that property: it is set automatically by Exchange, but the item in teh Sent Items folder in the cached store might not have it because most likely the item in never synchronized (this is due to bandwidth optimization trick by Outlook), so you might have to open the folder in the online mode using the MAPI_NO_CACHE flag, which OOM won't let you use - it is either Extended MAPI (C++ or Delphi) or Redemption (I am also its author - any language). See https://stackoverflow.com/questions/45952523/what-is-the-vba-property-for-server-folder-contains-x-itmes for an example.

Attachments missing on the EWS server for draft email saved via Outlook OfficeJS

I am using the Office.context.mailbox.item.saveAsync method for saving a draft email. This method returns itemId which I later use to make a call to the EWS server to retrieve the email eml content, but the returned eml content is missing some of the attachments.
This is only happening on the Desktop App (Outlook 2013) with cache mode enabled. When using Outlook on the Web it works correctly.
I am using ews-java-api to retrieve the email from the EWS.
Is there a way to know when the email saving is finished?
I can't use the Office.context.mailbox.item.saveAsync.makeEwsRequestAsync because of the 1MB response limitation.
In Cached mode it will take time for the item to sync up to the server. People usually poll until the data they want is there.
Also, they can write a custom property, and check for that property to make sure their item is up to date if necessary.
You can find some details about custom property here: Client Extension Message Object Protocol, Mail App Custom Properties and Mail App Accesses Custom Properties
Is there a way to know when the email saving is finished?
If the following: "Is there a way to know when the email saving is finished?" is your question, than the answer is No. You may try the ugly solution, when you use sub-sequential EWS query with Id you've got from saveAsync in the loop and wait for success. This may take, depend on environment, from a few seconds to like half a minute easily. Not sure if your customers (users) will wait for so long, when add-in finally respond.
You may get more information from the topic: App for Outlook: EWS request failed with item Id returned by item.saveAsync on compose new message
EDIT:
Simple GetItem request can be used as follow ...
<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<t:BaseShape>IdOnly</t:BaseShape>
</ItemShape>
<ItemIds><t:ItemId Id="' + itemId + '"/></ItemIds>
</GetItem>
The request should return ChangeKey if item was created on exchange.

Reading email body of email with RMS protection using MAPI

I have a C++ Oulook plugin that reads outgoing emails (during ItemSend event) and analyzes them. When sending an email and adding RMS permission, the PR_BODY_W property of the outgoing email contains (instead of the real body):
This message is protected with Microsoft Information Protection. You can
open it using Microsoft Outlook, which is available for iOS, Android,
Windows, and Mac OS. Get Outlook for your device here:
https://aka.ms/protectedmessage.
Microsoft Information Protection allows you to ensure your emails can't be
copied or forwarded without your permission. Learn more at https://microsoft.com/rms.
The real body is retrieved successfully with Outlook Object Model by calling MailItem.Body property.
However, is there a way to read the body using MAPI and not OOM?
The text in PR_BODY really is the real body. However, when Outlook finds an RMS attachment on a message, it substitutes what it finds in that attachment for the real body. The OOM masks this behavior for you. Using MAPI, you'll have to do the decode yourself.
RMS attachments in Outlook/Exchange messages is governed by [MS-OXORMMS]: Rights-Managed Email Object Protocol. Specifically, you're interested in Opening a Rights-Managed Email Message.
Here's the general outline:
Grab PidNameRightsManagementLicense from the message.
Locate attachments with a message class of "rpmsg.message"
Unzip the attachment following RFC 1950
Continue unpacking data from the attachment following the protocol doc.
...
Knowing that all of this is governed by OXORMMS, we can find the following project on GitHub which might be instructive: https://github.com/damico/test-inflate-rms.

Raw Headers in MS Outlook

I'm developing an Outlook Add-In (2007, VBA), which is supposed to send the raw Internet Headers of a MailItem to a Server, which then does some processing. With raw I mean before they are decoded.
I am aware of the GetInetHeaders-Function, but is there a way to get the headers before they are decoded by Outlook?
No, Outlook receives the message and decodes before it is saved and hence becomes visible through the Outlook Object Model or MAPI.
Why exactly do you need to do that?

CSV and send email: DA|Could not open the lock file at /tmp/DAAccountsLoading.lock. We'll load the accounts anyway, but bad things may happen

I'm trying to create a csv and send it via email.
I create an NSMutableArray of NSArray (called csvArray), use the Dave DeLong's CHCSVParser with:
[csvArray writeToCSVFile:filenameCSV atomically:YES];
Then, thanks to MFMailComposeViewController I can send this csv file in attachment to an email, but the first time I send the email I can read this in the debugger console (it appears when I add the recipient):
DA|Could not open the lock file at /tmp/DAAccountsLoading.lock. We'll load the accounts anyway, but bad things may happen
EDIT
This message appears also if I don't attach any files.
Dave DeLong's CHCSVParser works perfectly.
Has anyone come across such a message using MFMailComposeViewController?