Applescript: Deleting attachments and message size

M

Mike D

This is a question for the Applescript gurus out there...

I wrote a script for deleting the attachments from a mail message
(below). I'm getting some weird behavior of the message size when
deleting the files by AppleScript, which I don't get when deleting
them manually with the "remove" button in the message.

As an example: I receive a mail with 3 attachments:
Attachment 1: 3 MB
Attachment 2: 2 MB
Attachment 3: 1 MB

When I select all the attachments in Entourage, then click on the
"remove" button, the message size goes to some trivially small size.
When I use the AppleScript, even though all the attachments are
supposedly deleted (according to the "History" in the message window),
the file size is reported as 5MB, reflecting only the change of
deleting the last attachment (the script starts at the last one and
goes to the first one, deleting them in order). The point is that
after deleting the first file in the list, the message size isn't
updated in Entourage.

This doesn't happen when deleting attachments manually, by selecting
them and hitting the "Remove" button in the message window.

Is there some AppleScript command to tell Entourage to recalculate the
message size? Is there another way to write the script to make it
correctly calculate the message size? This may sound like a trivial
problem, but at my work, we have a low limit on the size of our
mailboxes, and Entourage/Exchange thinks I have big files in my
mailbox when I don't.

Thanks!
--Mike

----- Script

tell application "Microsoft Entourage"
try
activate
set theMsg to item 1 of (get current messages)
set attachCount to count of the attachments of theMsg
set attachedFiles to the attachments of theMsg
repeat with i from attachCount to 1 by -1
set theAttachment to item i of attachedFiles
delete theAttachment
end repeat
end try
end tell

----- End Script
 
B

Barry Wainwright [MVP]

Simple answer is that you're doing nothing wrong. I hadn't noticed this
effect before, but I'll check it out. There is no 'refresh' command in
applescript for Entourage.

--
BarryW
Microsoft MVP (see http://www.microsoft.com/mvp for details)
Visit the Entourage User's Weblog for hints tips & troubleshooting for
Microsoft entourage: http://www.barryw.net/weblog

From: Mike D <[email protected]>
Organization: http://groups.google.com
Newsgroups: microsoft.public.mac.office.entourage
Date: Thu, 01 Nov 2007 16:31:39 -0000
Subject: Applescript: Deleting attachments and message size
This is a question for the Applescript gurus out there...

I wrote a script for deleting the attachments from a mail message
(below). I'm getting some weird behavior of the message size when
deleting the files by AppleScript, which I don't get when deleting
them manually with the "remove" button in the message.

As an example: I receive a mail with 3 attachments:
Attachment 1: 3 MB
Attachment 2: 2 MB
Attachment 3: 1 MB

When I select all the attachments in Entourage, then click on the
"remove" button, the message size goes to some trivially small size.
When I use the AppleScript, even though all the attachments are
supposedly deleted (according to the "History" in the message window),
the file size is reported as 5MB, reflecting only the change of
deleting the last attachment (the script starts at the last one and
goes to the first one, deleting them in order). The point is that
after deleting the first file in the list, the message size isn't
updated in Entourage.

This doesn't happen when deleting attachments manually, by selecting
them and hitting the "Remove" button in the message window.

Is there some AppleScript command to tell Entourage to recalculate the
message size? Is there another way to write the script to make it
correctly calculate the message size? This may sound like a trivial
problem, but at my work, we have a low limit on the size of our
mailboxes, and Entourage/Exchange thinks I have big files in my
mailbox when I don't.

Thanks!
--Mike

----- Script

tell application "Microsoft Entourage"
try
activate
set theMsg to item 1 of (get current messages)
set attachCount to count of the attachments of theMsg
set attachedFiles to the attachments of theMsg
repeat with i from attachCount to 1 by -1
set theAttachment to item i of attachedFiles
delete theAttachment
end repeat
end try
end tell

----- End Script
 
M

Mike D

Thanks for the replies, and the reassurance that the script *should*
work!

I looked through the scripts that Diane linked to, and from what I
could tell, they use a much simpler way of deleting the attachments.
Instead of iterating through like I had written above, the script
would look like:

----- Script

tell application "Microsoft Entourage"
try
activate
set theMsg to item 1 of (get current messages)
delete theMsg's attachments
end try
end tell

----- End Script

This seems to work. In my test message with 3 attachments, each 460k,
deleting the attachments by the script in my first message makes the
final size 921k (only the last attachment's size is subtracted from
the 1.3 MB total), while with the script just above, the message size
is 1.4k.

So if you want to delete *all* the attachments, then go for this
method, and don't iterate through them. If you want to only delete
certain messages, I guess you may have to deal with this little
message size issue. I guess that more or less answers my question, but
I'm still curious as to why it works that way.

Thanks!

--Mike
 

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