Get "mail attachments" fails with "-10000" general error - OS X 10.10.1

All, There appears to be a very reproducible error “-10000” “Apple Event Handler” regarding the access / use of Apple Mail email attachments by the OS X applescript terms “mail attachments” in OS X V10.10.1 yosemite. (2014/2015") .

I’d like to entertain any expertise on the matter. Please realise that the syntax (usage) is correct because the applications using the “mail attachments” facility have been in production for 7-8 years and are now inoperable in OS X 10.10.1

Any Apple Script or automator object that references “mail attachments” fails with OS return code “-10000” with error info as “Apple event Handler”.

For the sake of brevity and to focus on the precise issue, these EXAMPLE script snippets have ready access to Active Mail.app’s the current set of email(s) via OSASCRIPT, Applescript, Automator, Selection or other in var called “processing_email_messages” as :

tell application "Mail" to set processing_email_messages to 

… any email or list

Example #1

tell application "Mail" to get count of mail attachments of first item in processing_email_messages 

Example #2

if current_email's mail attachments is not {} then

Example #3

 tell application "Mail" to get count of the mail attachments in (first item in processing_email_messages) 

This has been reproduced on 6 independent / different 10.10.1 OS X systems and different users spaces (logons ~/)with the same error symptoms and therefore conclude that this issue is within the current OS X 10.10.1.

Symptom of any of these in any construct:
AppleScripts:
error “Mail got an error: AppleEvent handler failed.” number -10000

Automator: with nodes Get Selected Mail Messages ->> Get Attachments from Maill Messages
Get Attachments from Mail Messages Failed - Error 1
An error occurred while executing a script: The Operation couldn’t be completed. (OSStatus error -10000)

/var/syslog/system.log: these are very consistent.
Mail[49641]: *** Assertion failure in -[MCMimeBody dataForMimePart:], /SourceCache/Mail/Mail-1993/MailCore/MIME/MCMimeBody.m:362
Mail[49641]: An exception was thrown during execution of an NSScriptCommand…
Mail[49641]: This method must be called off the main thread

It appears form web searches that this is not unique to myself as many others have the precise issue that is UNRELATED to syntactic use of Applescript in OSx Mail.app.

I’d appreciate any help or comments on the matter or a workaround would be also very helpful.

Many Thanks
Warwick
Hong Kong

Model: OSX 10.10.1, email processor, automator, applescript
AppleScript: OSX 10.10.1 Yosemite
Browser: Safari 600.2.5
Operating System: Mac OS X (10.8)

I’m really puzzled.
Here mail attachments seems to behave flawlessly.
For tests, I created a mailbox in which I moved a message with two attached pictures.
I ran a short script and you may see the results in comments :

tell application "Mail"
	count messages of mailbox "abc"
	--> 1
	count mail attachments of message 1 of mailbox "abc"
	--> 2
	mail attachments of message 1 of mailbox "abc"
	--> {mail attachment id "1.2" of message id 29686 of mailbox "abc" of application "Mail", mail attachment id "1.3" of message id 29686 of mailbox "abc" of application "Mail"}
	
	properties of mail attachments of message 1 of mailbox "abc"
	--> {{downloaded:true, MIME type:"image/bmp", name:"Pièce jointe.bmp", file size:4494, class:mail attachment, id:"1.2"}, {downloaded:true, MIME type:"image/bmp", name:"Pièce jointe.bmp", file size:1398, class:mail attachment, id:"1.3"}}
end tell

If your first script was complete, it would have been easier to run your different tests.
As far as I know, tell application “Mail” to set processing_email_messages to
is not a complete instruction.

Yvan KOENIG (VALLAURIS, France) dimanche 18 janvier 2015 12:48:24

Hello Yvan thanks for your reply, I was hoping you might be one to offer advice. Firstly the "instruction/statement " you mention obviously won’t parse…, I assuming those with expertise would assume correctly that the “to some_varnam” was suffixed😉 assume the statements have superfluous info omitted

That said, I’m surprised you did not experience this -10000 error as it has been quite frustrating to find a workaround.

Simply using one of this examples below with single statement with mail.app active AND. A selection will always fail for us

Looking at your example, Id like to add that I DID NOT specifically address a mailbox in these statements .
The actually error had appeared in a series of mail rules the instant we used them with OSX 10.10.1 .

The code unit is tasked an array of mail messages, not a whole mailbox. Perhaps you might verify this for me .

With the exception of “mail attachment” all else seems to work with “mail” in AppleScript

I will add keywords to existing statements to force them to specifically address the message in the MAILBOX rather than assuming the one handed to the ode from a rule or even a selection or from an Automator test stub

Unit testing these fragments has led me to this post as it appears these code statements have been error free for years. Thus I believe the usage sound and should not require recoding for 10.10.1

I thing the error logged “must be run from main thread” offers a keys to the root if this issue.

Thanks for looking at this I’m afraid that this looks like an actual is 10.10.1 flaw

Kind regards
Warwick
Hong Kong

I made complementary tests and got the error -10000 for some message belonging to the account iCloud.

Here is the script used for tests :

tell application "Mail"
	set processing_email_messages to (get selection)
	set messages_with_attachments to {}
	repeat with i from 1 to count processing_email_messages
		set aMessage to item i of processing_email_messages
		# Try block required because here an error is issued when a message belongs to account iCloud
		try
			if (count mail attachments of aMessage) > 0 then
				log aMessage
				set end of messages_with_attachments to aMessage
			end if
		on error errMsg number errNbr
			log "error # " & errNbr & return & errMsg
		end try
	end repeat
	messages_with_attachments
end tell

Honestly, I’m surprised by the fact that you missed the link between the encountered error and the account owning the messages.

Yvan KOENIG (VALLAURIS, France) dimanche 18 janvier 2015 15:31:29

I continued my search.
The messages which issued an error are those containing large attachments which are not embedded in the raw content.
These objects have this kind of descriptor :

Content-Transfer-Encoding: BASE64
Content-Disposition: ATTACHMENT;
filename=P1070542.jpg
Content-Type: IMAGE/JPEG;
name=P1070542.jpg
X-Apple-Content-Length: 991146

I don’t know the exact limit but here are some lengths which gave the error :

1,820,944
1,241,316
991,146
703,180
526,782
189,484

I have a message with an attached Pages package which is embedded with a scheme which I don’t understand :
its header is :

Content-Disposition: ATTACHMENT;
filename=“Menu Rework Sep 2014.pages.zip”
Content-Type: APPLICATION/ZIP;
name=“Menu Rework Sep 2014.pages.zip”;
x-mac-auto-archive=yes
Content-Transfer-Encoding: BASE64

but when the message is displayed, the document appear as a normal Pages document, not a zipped one.
The package is 7,345,701 bytes long,
7,240,724 ones when zipped.

Yvan KOENIG (VALLAURIS, France) dimanche 18 janvier 2015 16:48:48

Hello Yvan, again thank you for your comments and advice. To be very very clear and concise, For you and others reviewing this issue and attempting to derive a resolution or workaround for this issue, I will be VERY SPECIFIC about the scenario to avoid any confusion with the:

  1. syntax, punctuation and usage of the statements by consolidating the issue into a single easy to grasp statement that causes the -10000 Apple Event Hander Error
  2. this error happens when the statement included the term "mail attachments" is use against ANY  Apple OS X MAil.app account with ANY IMAP account on any MAC 10.10.1 system on any user (several) that is accessing on any EMAIL server referenced in the APPLESCRIPT environment and as you point out even  iCloud accounts. (The original error was not drawn in any child accounts as these are not used with this MAIL RULE or Automator script
  3. we maintain our own in-house email server as well under OS X SERVER ,  APPLE OSX Server HOSTED, happens on these too, and this is again reproducible from gmail account if you have to use those blokes.
  4. the type or mime type or size or the number of the attachment is irrelevant . It happens with only one attachment.
  5. the error was appaent initially on OS X 10.10.1 in several email rules under OS X Mail.app.
  6. it is easily reproducible from the script editor or Automator with an active email application
  7. the error manifests itself continually as:

in UI or SCRIPT or as described in OP

and in /var/log/system.log

this statement will ALWAYS fail with -10000 Apple Event Handler

  1. to add to your test case, simply send and email with an attachment to an email account in your Apple mail.app mailbox to account EXAMPLE "your_account_on_a_server_somewhere@your_email_somewhere.com).

In it’s receipt, kick off the Apple Script editor and run list line… AGAIN… use YOUR email account for the string “your_account_on_a_server_somewhere”

tell application "Mail" to set current_mail_account_mailboxes_inbox_first_message_attachments_attachment_count to count of attachments in mail attachments of (last message of mailbox "INBOX" of account "your_account_on_a_server_somewhere")

If readers are not sure of what they have in the way of accounts on the CURRENTLY LOGGED IN USER in their Mail.app simply access the preferences and use the string in the preferences/accounts/account information/ description or simply pull/run/execute this statement in a script editor as:

get every account

Lastly this error is not unique to our macs as others have a similar issue. Sadly is not an local to our own MAC environment.

Cheers and thanks again from Hong Kong
Warwick

I selected every mailboxes (50) then typed command + A so Mail said that 10,503 messages were selected.
One account is an iCloud one (imap)
One is a Gmail one (imap)
Three are SFR ones (pop)
One is a LaPoste one (pop)
I apologize but I must repeat that on my machine, only 24 messages from my account iCloud issue the error #-10000.
Some are in the INBOX mailbox, other are in the Sent Messages of the named account.
Of course, it may be because only messages in my iCloud account have large attachments.

May you try to replace your instruction :

tell application "Mail" to set current_mail_account_mailboxes_inbox_first_message_attachments_attachment_count to count of attachments in mail attachments of (last message of mailbox "INBOX" of account "your_account_on_a_server_somewhere")

by

tell application "Mail" to set current_mail_account_mailboxes_inbox_first_message_attachments_attachment_count to count mail attachments of (last message of mailbox "INBOX" of account "your_account_on_a_server_somewhere")

As far as I know, a mail attachment doesn’t contain an attachment, it is an attachment.

Yvan KOENIG (VALLAURIS, France) lundi 19 janvier 2015 12:03:27

Hi Yvan, many thanks for your reply. Yes I have replaced the script statement copied EXACTLY from your paost nd changed the email account name. I’ve tried this various form of syntax prior to initial posting. I rather think it’s a defect/flaw with Application “mail” and the processing of the terms “mail attachment” in 10.10.1

so… it failed sadly.

tell application "Mail" to set current_mail_account_mailboxes_inbox_first_message_attachments_attachment_count to count mail attachments of (last message of mailbox "INBOX" of account "Gmail - warwick test account")

There is ONLY one email in this test gmail account. The attachment is a 30KB object of compressed, random blob… can be anything.

With my mail.app active (open) , The above statement it fails unfortunately with

/var/syslog/system.log

Looking forward to any other suggestions.

Thanks again Yvan.
warwick
Hong Kong

As I wrote, maybe it’s because it’s the only one containing messages with attachment breaking a “rule” that only my iCloud account is able to issue the error #-10000.

You may send the message which causes the problem on your machine to my gmail account.

My address is : yvankoenig gmail com

After sending this message I will boot in Mavericks.
Some of the messages for which I get the error #-10000 are old enough to be available in the volume using this operating system. I will see if I get the same behavior.

Yvan KOENIG (VALLAURIS, France) lundi 19 janvier 2015 13:50:27

Hi Yvan, again many thanks for your kind offer however I will decline it because the error is unrelated to the actual attachment size, type or number of them.

For example, I can attach a single, modest or outrageous (300x) attachments of various size WITHIN the limited of the EMAIL sendmail attachment size quota, email it and then the processes the RECEIVED INBOX statement we’ve been dealing with in previous post will fail.

I can confirm in the last 10 minutes that I DO NOT GET THE ERROR on OS X 10.9.x or as far back as OS X 10.5. I CONFIRM that the set of applescripts that use these “mail attachment” terms, functions correctly on one of our OS X 10.9.x netboot (complete) test and diagnostic systems.

So seems related to OSx 10.10.x

Looking forward to any further comments.

Thanks again

Warwick
Hong Kong

As I wished to be sure that I will have the “offending” messages in Mavericks, on my Yosemite volume, I moved them from INBOX of iCloud into a “standard” mailbox named “aaa”.
When I was in Mavericks, I imported these messages.

After the import process, under Mavericks, I selected all the messages available in my iCloud INBOX and ran the script : I didn’t got the error #-10000.
Then I selected the imported messages and ran the script : no more error #-10000.

Back under Yosemite, I selected the messages from the mailbox “aaa” and ran the script.
No more error #-10000.
I tried to move back the messages in the INBOX of iCloud account but no luck, some of them moved correctly, others remained in “aaa”.

As I am curious, I forwarded one of the message which gave the error #-10000 to my gmail address.
At this time I didn’t received it.

Yvan KOENIG (VALLAURIS, France) lundi 19 janvier 2015 14:54:30

Hi,

This solved my problem with mail attachments error -10000 in AppleScript and Automator on my MacBook

Step 1: Quit Application Mail and delete files

Envelope Index
Envelope Index-shm
Envelope Index-wal

from Library/Mail/V2/MailData

Step 2: Restart Mail und Rebuild Mail database

cheers

Mario

Hi All,

FYI

I filed a bug report (below) with Apple: Nov. 2014 . Apple closed my Bug report on this as a duplicate
BUG REPORT:
As of 10.9 and 10.10 ( Yosemite) you can no longer access Mail.app’s ‘mail attachments’ from Applescript.

This means you cannot save or count them.
You will 9 times out of 10 get resulting error “error “Mail got an error: AppleEvent handler failed.” number -10000”
This appears to happen for 90% of the emails that are in an inbox, individual or consolidated ones.
This bug is reproducible when using a “get selection” Applescripts
This bug is reproducible when Performing a “Run Applescript” action in the Mail.app mail Rules

Hopefully apple will fix this soon.

Hi Mario,thanks for your comments. I believe you have just been lucky or fortunate that this procedure changed “something” on out mac’s ~/ account that caused data examination form the “mail attachments” code path not to fail on OS X 10.10.1.

Certainly the removal of those Apple Mail indexes (a good old trick) causes a rebuild (which one may do indirectly to a less effective manner) through the Mailbox Application menu.

Our testing has manifested this error 99% of the time with a NEW mail account with a single message or the other extreme a 2001 email box with an inordinate number of messages and attachments.

Yvan made a point of this earlier.

Sadly this is looks still like a DEFECT in the implementation of the Applescript term “mail attachments” in OSx 10.10.1.

Form our experience so far, keep your fingers and legs crossed because this failing symptom will return when you least expect it… good Luck!

Warwick
Hong Kong

Hi Mark, yes I recall running over whilst searching this issue your post or similar somewhere that this issues had been logged with Apple. Thanks for doing this back in November. We have only seen this since December when we migrated all out production stuff from OS X 10.9.5 to 10.10.1.

AN adjuct to this albeit “noise” was that SOME OS X 10.7.x Apple Script mail terms caused -11000 and -10000 failures with “assertion” errors and “thread out of line” messages and Apple resolved this expeditiously at the time. Although, I am surprised that seeing a fair few of us have had this issue that it was not seen during Yosemite beta testing…

I agree with your own findings that this is a DEFECT in the processing of the term “mail attachments”. I’d like a workaround of course.

Alas we will have to wait and deal with our situation manually as we rely somewhat on APPLE Mail rules.

All, thanks again for your comments and ideas.

I will update this thread and close it once a satisfactory resolution is found.

Warwick
Hong Kong

Of late poster twtwtw on  apple discussion forums https://discussions.apple.com/thread/6782947 made mention of a likely mail “cache” issue.

We had looked at something similar and looked again and could not find anything definitive in 10.10.1.

The information is at a recent post at https://discussions.apple.com/thread/6782947 and won’t be duplicated here.

any clues would be graciously accepted.

warwick
Hong Kong

Don’t know why but I was hoping that since apple have screwed some of the commands in JXA , like not being able to get the album art using rawdata of data for iTunes. Then maybe they had done the reverse here.

So tried it.

Mail = Application('Mail')

var theAtt  =Mail.selection()[0].mailAttachments()[0].name()

theAtt 

//--On My Mac mailbox: --> "photo 1.JPG"

//--iCload  mailbox: --> Error -10000: AppleEvent handler failed.

And pretty much the same results. Same email but one stored in mailbox ‘On My Mac’ and one in the inbox (icloud)

On My Mac mailbox: → “photo 1.JPG”

iCload mailbox: → Error -10000: AppleEvent handler failed.

I have had more luck with emails stored in ‘On My Mac’ than ones referenced to the inboxes. But have had the issue there also.

I really do think the issues is not the emails or attachments but how Apple have implemented changes in Mail.app or Applescript

Hi Mark, that’s also very interesting. Thanks for that post. This flaw in the “mail attachment” term processing will have to be addressed by an Apple OS X internal s/w fix and I have resigned to having to wait for it.

BTW for you and other readers the continued thread fro Apple forums user twtwtw has some reasonable views concerning this issue.

The thread is at: https://discussions.apple.com/thread/6782947

Thanks again.

Warwick
Hong Kong

I hope you guys are logging all these problems at bugreport.apple.com. That’s the best way you can try to influence things.

Hi Shane, yes fair point! yeah this has been logged apparently by a few people since November 2014, including one of the people in this thread. Two people have pointed out that it has been accepted or made a DUPLICATE or some terminology that means it has been acknowledged as a defect by Apple.

[whinge] I hope it’s resolved soon OS X 10.10.2 because the production workflows we use from clients has some reliance on this term “mail attachment” in our mail rules.

cheers mate

Warwick
Hong Kong