Mikael Byström wrote:

>I'm interested enough in the problem to look at scripting solutions.
>Cheshirekat wrote "Rename Existing Attachments" so that is probably a
>great starting point. Anyone else have already done such a thing?

Well, I have resorted to wrapping up all attachments of a single email
into a folder named like "2001-5-9 10-36 <[EMAIL PROTECTED]>".

I use it in a filter like:

[x] Incoming
Conditions: [always]
Actions: [Run AppleScript][Wrap Attachments.scpt]

Mind that this script is quite fragile, but it does its job most of the
time, and it was written with my special situation in mind. When it
fails, I don't have tracked so far. I can figure different messages sent
at the same time from the same person with different attachments - this
will probably fail (and is not fully unlikely). Maybe one should also
create some hash-based value for folder naming of the email properties.

Anyway, here's the script - I'm sure there's much room for improvement:

--snip--
global theFolder

tell application "PowerMail"
        set attachFolder to attachment folder
        
        set theMessages to current messages
        repeat with msg in theMessages
                set msgStatus to status of msg
                if (msgStatus is unread) or (msgStatus is confirmed) or 
(msgStatus is
read) then
                        set attachList to attachments of msg
                        if (count items of attachList) > 0 then
                                set theDate to time received of msg
                                set msgAttachFolder to ""
                                set msgAttachFolder to msgAttachFolder & (year 
of theDate)
                                set msgAttachFolder to msgAttachFolder & "-"
                                set msgAttachFolder to msgAttachFolder & (month 
of theDate as number)
                                set msgAttachFolder to msgAttachFolder & "-"
                                set msgAttachFolder to msgAttachFolder & (day 
of theDate as number)
                                set msgAttachFolder to msgAttachFolder & " "
                                set msgAttachFolder to msgAttachFolder & 
(((time of theDate) / 3600)
as integer)
                                set msgAttachFolder to msgAttachFolder & "-"
                                set msgAttachFolder to msgAttachFolder & 
((((time of theDate) mod
3600) / 60) as integer)
                                set msgAttachFolder to msgAttachFolder & " <"
                                set senderAddress to sender of msg
                                set msgAttachFolder to msgAttachFolder & (email 
address of senderAddress)
                                set msgAttachFolder to msgAttachFolder & ">"
                                tell application "Finder"
                                        if not (exists folder (attachFolder & 
msgAttachFolder as string)) then
                                                set theFolder to (make new 
folder at attachFolder with properties
{name:(msgAttachFolder as string)})
                                        else
                                                set theFolder to folder 
(attachFolder & msgAttachFolder as string)
                                        end if
                                end tell
                                repeat with attachIdx from (count items of 
attachList) to 1 by -1
                                        set attachFile to file of (item 
attachIdx of attachList)
                                        tell application "Finder"
                                                set newAttachFile to (move 
attachFile to theFolder without
replacing) as alias
                                        end tell
                                        delete attachment attachIdx of msg
                                        make new attachment at msg with 
properties {file:(newAttachFile as
alias)}
                                end repeat
                        end if
                end if
        end repeat
end tell
--snip--

The attachment move/rename part was most probably copied from the
"Reattach lost attachments" script, and I do not claim any originality
of any part of it.

HTH,
Christian





Reply via email to