Cannot replace deleted mailboxes in 'Mail.app'

G’day Scripters

In my app, I create new mailboxes my year/month/day, using Mail.app.

While checking the code, I deleted the new mailboxes, and now my code refuses to re-create them, except for the ‘Year ’ mailbox. There seems to be a ˜ghost’ of the old month and daily mailboxes stopping the handler.

Does anyone know how to fix this please? I’ve tried re-building and re-starting Mail.

Regards

Santa


property t : ""
set my t to "2014 06 09 _test ftpSaving"
set tt to (word -5 of my t & " " & word -4 of t & " " & word -3 of t)
set tempYearString to ("Year " & word -5 of my t as text)
set TempMonthString to word -4 of my t as text
tell application "Mail"
	if not (exists mailbox tempYearString) then
		make new mailbox with properties {name:tempYearString}
	end if
	set p to 9
	delay 0.2
	if not (exists mailbox TempMonthString of mailbox tempYearString) then
		say 1
		make new mailbox with properties {name:tempYearString & "/" & TempMonthString}
	end if
	if not (exists mailbox tt of mailbox TempMonthString of mailbox tempYearString) then
		say 2
		make new mailbox with properties {name:tempYearString & "/" & TempMonthString & "/" & tt}
	end if
end tell

Model: Late 2014 retina i7, Yosemite
AppleScript: 2.4
Browser: Safari 600.2.5
Operating System: Mac OS X (10.10)

Hi,

is that AppleScriptObjC related? :wink:

Get the names and look if the mailboxes are still there


tell application "Mail"
	set mailBoxNames to name of mailboxes
end tell

You could delete them programmatically, too

G’day Stefan

It is ASObjC related. The main part of the code is in one of my projects. I’ve just re-written the code snippet to stand alone.

I seem to recollect reading about this very problem several years ago, with a remedy, but did not bookmark it. Several hours of searching have not relocated the item.

I’ve re-written the handler, below, to throw an error, and the old deleted mailboxes are not listed. I’ve also tried deleting the old deleted mailboxes pragmatically, just in case they could still be recognized.


property t : ""
set my t to "2014 06 09 _test ftpSaving" as text
set tt to (word -5 of my t & " " & word -4 of t & " " & word -3 of t)
set tempYearString to ("Year " & word -5 of my t as text)
set TempMonthString to word -4 of my t as text
tell application "Mail"
	try
		if not (exists mailbox tempYearString) then
			make new mailbox with properties {name:tempYearString}
		end if
		set p to 9
		delay 0.4
		if not (exists mailbox TempMonthString of mailbox tempYearString) then
			make new mailbox with properties {name:tempYearString & "/" & TempMonthString}
		end if
		delay 0.4
		if not (exists mailbox tt of mailbox TempMonthString of mailbox tempYearString) then
			make new mailbox with properties {name:tempYearString & "/" & TempMonthString & "/" & tt}
		end if
	on error errmsg
		display dialog errmsg
	end try
end tell
tell application "Mail"
	set mailBoxNames to name of mailboxes
end tell

I’ve found the answer. Very slow, but working.

Santa


property t : ""
set my t to "2014 06 08 _test ftpSaving" as text
set folderDailyNameTemp to (word -5 of my t & " " & word -4 of t & " " & word -3 of t)
set tempYearString to ("Year " & word -5 of my t as text)
set TempMonthString to word -4 of my t as text
set c to current date
tell application "Mail"
	activate
	tell application "System Events" to tell process "Mail"
		click menu item "Message Viewer" of menu 1 of menu bar item "Window" of menu bar 1
	end tell
	tell message viewer 1
		set mailbox list visible to true
	end tell
	try
		set p to 1
		if not (exists mailbox tempYearString) then
			make new mailbox with properties {name:tempYearString}
		end if
		set p to 2
		delay 1
		if not (exists mailbox TempMonthString of mailbox tempYearString) then
			set p to 3
			set selected mailboxes of message viewer 1 to mailbox tempYearString
			set p to 4
			tell application "System Events" to tell process "Mail"
				click menu bar item "Mailbox" of menu bar 1
				delay 0.1
				click menu item "Rebuild" of menu 1 of menu bar item "Mailbox" of menu bar 1
				set p to 5
			end tell
			delay 0.1
			repeat until exists mailbox TempMonthString of mailbox tempYearString
				try
					make new mailbox with properties {name:(tempYearString & "/" & TempMonthString as rich text)}
				end try
				delay 0.1
			end repeat
		end if
		activate
		set p to 6
		if not (exists mailbox folderDailyNameTemp of mailbox TempMonthString of mailbox tempYearString) then
			set selected mailboxes of message viewer 1 to mailbox TempMonthString of mailbox tempYearString
			set p to 7
			tell application "System Events" to tell process "Mail"
				click menu bar item "Mailbox" of menu bar 1
				delay 0.1
				click menu item "Rebuild" of menu 1 of menu bar item "Mailbox" of menu bar 1
				set p to 8
				delay 0.1
			end tell
			delay 0.1
			repeat until exists mailbox folderDailyNameTemp of mailbox TempMonthString of mailbox tempYearString
				try
					make new mailbox with properties {name:(tempYearString & "/" & TempMonthString & "/" & folderDailyNameTemp as rich text)}
				end try
				delay 0.1
			end repeat
		end if
	on error errmsg
		display dialog errmsg & " p = " & p as rich text
	end try
end tell
say (current date) - c --< 30 seconds, 1 second if already existing