Extracting PDF files from Mail.app and renaming them with current date

Stefan, great job, this is working perfect.

In fact the problem was with the message ID that seems to be not assigned when processing rules.

Last question. How can I include code in your script, so that only pdf files larger than 100 kb are to be processed ?

replace

if MIME type of thisItem is "application/pdf" then

with


if MIME type of thisItem is "application/pdf" and file size of thisItem > 100000 then

Stefan,

I don’t know if you are still online on this forum.

I have upgraded OSX Lion and your script does not work anymore.

Do you have any ideas ?

Thanks.

The save line throws always an error.
I tried to put the Scripting Additions commands out of the scope of Mail and also specified the path as POSIX path.
No success.

It seems to be a bug

Yes, there has to be a bug…

Should I refer this bug to Apple ?

Any help would be appreciated :slight_smile:

Is there no way round this bug?

I think I need to re-install Snow as we have come to rely on this very handy script!

I have posted it on the Apple forums but not reported it as a bug yet.

Upgrading = Foolish Me

Thanks. I also posted this bug to apple but i got no reply.

This script is paramount for me, so any help in this regard would be really appreciated.

I am trying some variations but to no joy.

Is there any work around for this in the short time? I am playing with the idea of forwarding the emails to a box net folder that is synced on my desktop but it is not as clean as this script was.

Do any other mail applications offer the ability to save attachments automatically?

seems like we are still stuck :frowning:

Any update on this ? Has anyone succeeded in having this script working under Lion ?

Hello

Can someone help my upgrade the script so that it works with MaxOS Sierra ? 😛

Currently this script does not function correctly anymore and when I initiate the rule in Mail.app that runs this script, I get this error in the console :


using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		set dt to path to desktop
		#set outputPath to (dt as rich text) & "Incoming OCR:"
		set outputPath to "/Users/john/Incoming OCR/"
		set x to 1
		repeat with thisMessage in theMessages
			tell mail attachments of thisMessage to set {attachs, cnt} to {it, count it}
			set y to 1
			repeat with thisItem in attachs
				try
					if MIME type of thisItem is "application/pdf" and file size of thisItem > 2000 then
						tell ((date received of thisMessage) as «class isot» as string) to ¬
							tell ((date received of thisMessage) as «class isot» as string) to ¬
								rich text 1 thru 4 & "-" & rich text 6 thru 7 & "-" & rich text 9 thru 10 & "-" & ¬
								rich text 12 thru 13 & "." & rich text 15 thru 16
						
						
						save thisItem in (POSIX file (outputPath & result & "-#" & file size of thisItem & ".pdf"))
						set y to y + 1
					end if
					if MIME type of thisItem is "image/jpeg" and file size of thisItem > 30000 then
						tell ((date received of thisMessage) as «class isot» as string) to ¬
							tell ((date received of thisMessage) as «class isot» as string) to ¬
								rich text 1 thru 4 & "-" & rich text 6 thru 7 & "-" & rich text 9 thru 10 & "-" & ¬
								rich text 12 thru 13 & "." & rich text 15 thru 16
						
						save thisItem in (POSIX file (outputPath & result & "-#" & file size of thisItem & ".jpg"))
						set y to y + 1
					end if
				end try
			end repeat
			set x to x + 1
		end repeat
	end perform mail action with messages
end using terms from