Why does this Mail archiving script consume 40 GB app memory?

you’re right of course. This would be so much easier if they just had ID’s …

I did not have an error from the “count messages” code. I did change “mboxName” to “INBOX” as shown below and your script works great, gmail and all.

This:

tell mailbox mboxName of account id accntID

Was changed to this:

tell mailbox "INBOX" of account id accntID

1 Like

Now if only it ran just a wee bit faster …

I discovered that your script would not work for my specific needs. I created a mailbox and a rule to move specific messages to it. I can then process just those specific messages. Since the mailbox is not a INBOX, your script fails due to missing message IDs. I found a simple script that works for me. It seems to be fast with plain text email messages. At some point I plan to combining this script with your script. I thought it might be a good solution for you as well.

This script is modified from the source script noted below.

--> SRC: https://veritrope.com/code/export-apple-mail-messages-and-notes-to-text-files/

set SaveLoc to (path to desktop)

set successCount to 0

tell application "Mail"
	
	if (selection is not {}) then
		set theMessages to selection
		set msgnr to 1
		repeat with thisMessage in theMessages
			set myTitle to the subject of thisMessage
			set myContent to the content of thisMessage as rich text
			set ReplyAddr to the reply to of thisMessage
			set EmailDate to the date received of thisMessage
			set theSource to the source of thisMessage
			
			(*CLEAN TITLE FOR FILE *)
			set previousDelimiter to AppleScript's text item delimiters
			set potentialName to myTitle
			set legalName to {}
			set illegalCharacters to {".", ",", "/", ":", "[", "]"}
			repeat with thisCharacter in the characters of potentialName
				set thisCharacter to thisCharacter as rich text
				if thisCharacter is not in illegalCharacters then
					set the end of legalName to thisCharacter
				end if
			end repeat
			
			set AppleScript's text item delimiters to ""
			
			if length of legalName is greater than 32 then
				set legalName to (items 1 thru 32 of legalName) as rich text
			else
				set legalName to legalName as rich text
			end if
			
			set AppleScript's text item delimiters to previousDelimiter
			set theFileName to legalName
			
			(*EXPORT TO TXT FILE *)
			set theText to myContent
			set theFilePath to (SaveLoc & msgnr & "-" & theFileName & ".txt") as string
			set msgnr to msgnr + 1
			set theFileReference to open for access theFilePath with write permission
			write theText to theFileReference as «class utf8»
			close access theFileReference
			set successCount to successCount + 1
		end repeat
		
	end if
	
end tell