MAIL: mailbox and NSInternalScriptError

Hello

I hope that someone can help me out because I dont know.

I would like to create a new mailbox and move some messages arround

set mboxName to "test"
set mbox to mailbox named mboxName

-- al those lines doesn't work
move eachMessage to mailbox named mboxName
move eachMessage to mailbox named "test"
move eachMessage to mailbox "test"
move eachMessage to mailbox mbox

-- when i want to create a new mailbox
make new mailbox with properties {name:"test2"}
make new mailbox with properties {name:mboxName2}
--

Always I get a NSInternalScriptError
What goes wrong? Is there a workarround? Or is Tiger really broken about this

Thanks

Hi,

This works for me if the mailbox exists and some messages are selected.

tell application "Mail"
	set mboxName to "test" -- if a mailbox with this name exists.
	set myMessages to selection -- If messages are selected.
	move myMessages to mailbox mboxName
end tell

How are you getting the variable ‘eachMessage’?

John M

Thanks John M for your reply.

I couldnt reply earlier because I was banned, but I am back again ( thanks Roy for the back again part of cource :slight_smile: ).

If I use this then I get every message three times copied :confused:

tell application "Mail"
	set mboxName to "Archive/aap" 
	--make new mailbox with properties {name:mboxName}
	set myMessages to (messages of inbox whose date received is less than ((current date) - (30 * days)) )
	move myMessages to mailbox mboxName
end tell

Why???

This is my orignial code and still not working.

property marker_archiveDays : 30
property mFolder_archive : "Archive"

tell application "Mail"
        set markerDate to ( current date - ( marker_archiveDays * days)) as date
	repeat with eachMessage in (every message in inbox whose read status is true)
		set msgDate to date received of eachMessage
		if (markerDate > msgDate) then
			set msgYear to year of msgDate as text
			set mboxName to mFolder_archive & "/" & msgYear
			log "mailbox : " & mboxName
			try
				set mbox to mailbox mboxName
				set mName to name of mbox
			on error
				if mboxName is not "" then
					make new mailbox with properties {name:mboxName}
					--set mbox to mailbox named mboxName
				end if
			end try
			move eachMessage to mailbox mboxName
		end if
	end repeat
end tell

a Second question

How can I use a second filter to filter my messages?

	set myMessages to (messages of inbox whose date received is less than ((current date) - (30 * days))
               AND whose read status is true )

but I can t find AND
or should it something like

	set myMessages to (messages of inbox whose date received is less than ((current date) - (30 * days))
	set myMessages to (messages of myMessages whose read status is true )

or should I make a loop with

repeat with i from 1 to number of items in myMessages

what should be more reliable?

Hi,

Trying to work with the ‘whose’ element as a date calculation wouldn’t work for me. This did (but it’s slow):

set mboxName to "test" -- mailbox name.
set myStart to (current date) - (30 * days) -- date of cutoff.
tell application "Mail"
	-- check for existance & make new mailbox if needed
	if name of mailboxes does not contain mboxName then make new mailbox with properties {name:mboxName}
	-- Refernce all the messages in the inbox
	set myMessages to get messages of inbox
	-- Make empty list
	set myList to {}
	-- Loop through the messages
	repeat with myMessage in myMessages
		-- If conditions are true add message reference to empty list.
		if (date received of myMessage) is less than myStart and (read status of myMessage) is true then set end of myList to myMessage
	end repeat
	-- Copy list of messages to mailbox.
       -- EDIT: Should be move not duplicate.
	--duplicate myList to mailbox mboxName
	move myList to mailbox mboxName
end tell

Hope this helps

John M

Hmmm I think I have a big problem.

All of the move samples gives me everything three times if it runs till the end.

see also in event log

	move {message id 519642 of mailbox "INBOX" of account "rvamerongen", message id 519639 of mailbox "INBOX" of account "rvamerongen", message id 519636 of mailbox "INBOX" of account "rvamerongen", message id 519712 of mailbox "INBOX" of account "rvamerongen", message id 519633 of mailbox "INBOX" of account "rvamerongen", message id 519630 of mailbox "INBOX" of account "rvamerongen", message id 519653 of mailbox "INBOX" of account "amerongen", message id 519642 of mailbox "INBOX" of account "rvamerongen", message id 519639 of mailbox "INBOX" of account "rvamerongen", message id 519636 of mailbox "INBOX" of account "rvamerongen", message id 519712 of mailbox "INBOX" of account "rvamerongen", message id 519633 of mailbox "INBOX" of account "rvamerongen", message id 519630 of mailbox "INBOX" of account "rvamerongen", message id 519653 of mailbox "INBOX" of account "amerongen", message id 519642 of mailbox "INBOX" of account "rvamerongen", message id 519639 of mailbox "INBOX" of account "rvamerongen", message id 519636 of mailbox "INBOX" of account "rvamerongen", message id 519712 of mailbox "INBOX" of account "rvamerongen", message id 519633 of mailbox "INBOX" of account "rvamerongen", message id 519630 of mailbox "INBOX" of account "rvamerongen"} to mailbox "test"
end tell

Some times I get NSInternalScripterror and other time others with the same code.
Also I notice that only one account is used. In my first code I did have them all.

Sometimes I can create a new mailBox other times not.
It look like when I got some ( (new) mail ) documents open I have more errors.
When I want to make a sub folder I can make it with a one line applescript but if I used in compleet script it gives error!
sight :frowning:

Anyway, thank you for your help.

R