Script help: Permanently delete an IMAP message

D

Doug

Hi,
Using: OS 10.3.3, Office X (latest rev), IMAP mail account

I'm trying to write a simple script that would allow me to select a range of
messages in an IMAP inbox, then permanently delete them. If I use the
command:

delete messagesToBeDeleted

The messages are simply moved to the deleted folder, when what I really want
is for them to be permanently deleted, i.e. gone from the deleted folder and
the IMAP server.

So, next idea. Just execute that same delete command twice...which doesn't
work. Apparently, when the messages are moved from the inbox to the deleted
folder, the message IDs are changed. It further appears that message IDs are
reused in a not easily predictable way (by me :), so the moved messages
won't be first or last in the deleted messages list, nor will they have the
highest or lowest message IDs.

So, next idea. Trying:
set connection action of SelectedMessage to remove at next connection

I haven't gotten this to do anything.

So, next idea. Mark all of these moved messages as untouched before I move
them to the deleted folder, then iterate through the deleted folder looking
for (and deleting) untouched mail. This works, but given that I like to
leave my non-Spam email in my deleted folder for a few months, I have way
too many messages to iterate through (perhaps 2,000) and this method is much
slower than just manually going to a custom view that has the filter I want,
selecting all and deleting.

....which brings me to the last thing I tried. Which is to use the trick I
described above (mark relevant messages-to-be-deleted as unread), then (with
Applescript) opening a custom view window on the relevant messages. This all
works as I would expect, but apparently, there is no way to get at the
message list content of a custom view window through Applescript.

So...I'm sure the answer is something like:
delete messagesToBeDeleted REALLY

....but I'm out of ideas. Any advice greatly appreciated.

Doug
 
P

Paul Berkowitz

Hi,
Using: OS 10.3.3, Office X (latest rev), IMAP mail account

I'm trying to write a simple script that would allow me to select a range of
messages in an IMAP inbox, then permanently delete them. If I use the
command:

delete messagesToBeDeleted

The messages are simply moved to the deleted folder, when what I really want
is for them to be permanently deleted, i.e. gone from the deleted folder and
the IMAP server.

That's standard in Entourage, in both the UI and AppleScript.
So, next idea. Just execute that same delete command twice...which doesn't
work. Apparently, when the messages are moved from the inbox to the deleted
folder, the message IDs are changed. It further appears that message IDs are
reused in a not easily predictable way (by me :), so the moved messages
won't be first or last in the deleted messages list, nor will they have the
highest or lowest message IDs.

Correct. That's also why 'move' and 'duplicate' won't work on the IMAP
server: the server cannot return a reply (the new message by ID) reliably
and the AppleScript commands move and duplicate require a result. 'delete'
does not require a result, but can't find the same message in the new
folder.
So, next idea. Trying:
set connection action of SelectedMessage to remove at next connection

That command is only for POP messages.
I haven't gotten this to do anything.

So, next idea. Mark all of these moved messages as untouched before I move
them to the deleted folder, then iterate through the deleted folder looking
for (and deleting) untouched mail. This works, but given that I like to
leave my non-Spam email in my deleted folder for a few months, I have way
too many messages to iterate through (perhaps 2,000) and this method is much
slower than just manually going to a custom view that has the filter I want,
selecting all and deleting.

...which brings me to the last thing I tried. Which is to use the trick I

described above (mark relevant messages-to-be-deleted as unread), then (with
Applescript) opening a custom view window on the relevant messages. This all
works as I would expect, but apparently, there is no way to get at the
message list content of a custom view window through Applescript.

Correct. I've been asking for it for years. I guess it's tricky because it
has to be continually updated.

You could try opening the custom view (that works), delaying for some amount
of time until all the results should be displayed (unreliable), selecting
all with GUI scripting (which in Entourage works for menu items, but not
buttons. I haven't tried emulating keypressing, but I think it will work.)
Then get the selection (a list of items) in Entourage, and delete it.
So...I'm sure the answer is something like:
delete messagesToBeDeleted REALLY

...but I'm out of ideas. Any advice greatly appreciated.

See above. Go to System Preferences/ Universal Access and check "Enable
assistive devices" to enable GUI scripting. Then

tell application "Microsoft Entourage"
open main window -- brings to front
set displayed feature of main window to custom view "Unread Deleted
IMAP" -- or whatever it's called
delay 10 -- or what you estimnate it takes to display all
activate
end tell

tell application "System Events"
tell application process "Microsoft Entourage"
keystroke tab
keystroke "a" using command down
end tell
end tell

tell application "Microsoft Entourage"
delete (get selection)
end tell




--
Paul Berkowitz
MVP Entourage
Entourage FAQ Page: <http://www.entourage.mvps.org/toc.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Entourage you are using - 2001 or X.
It's often impossible to answer your questions otherwise.
 
D

Doug

Thank you so much for a thorough and helpful response. I¹ll definitely give
your suggestion a try. I have never tried the GUI scripting, so I appreciate
the code snippets and setup information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top