Title: Re: Script to archive mail folders?
On or near 6/24/01 11:01 PM, Allen Watson at [EMAIL PROTECTED] observed:
> Do you script at all? Will some code snippets and suggestions suffice, or do
> you need someone to write the script for you? (I might be willing to take it
> on, or Paul; sounds fairly easy but fun.)
>
For example this handler might help you check for needed subfolders and to create them as needed:

-- Call example: my insure_folder_exists("2000-08", folder "Entourage Talk")
--Use "application "Microsoft Entourage" as parent for first-level folders

on insure_folder_exists(folderName, theParent)
    tell application “Microsoft Entourage”
    try
        get every message of folder folderName of theParent
    on error theErr number theNum
        if theNum = -1728 then
            make new folder with properties {name:folderName} at theParent
        else
            display dialog "Error " & theNum & ": " & theErr
        end if
    end try
    end tell
end insure_folder_exists

You could set the dates to search for something like this:

set theYear to 1999 -- Year BEFORE we want to start
repeat with i from 1 to 60 -- Allow for five year range
    set theMonth to (i mod 12) + 1
    set datestart to date ((theMonth as text) & "/1/" & theYear)
    if datestart > (current date) then exit repeat
    if theMonth = 12 then set {theYear, theMonth} to {theYear + 1, 1}
    set dateend to (date (((theMonth + 1) as text) & "/1/" & theYear)) - (1 * days)
-- Do your moving of folders here...
end repeat

To select files by date (date sent, I presume), here is some code I used in another script:

set msgs to (every message of theFldr) whose ((time sent >= datestart) and (time sent <= dateend))
        if (count of msgs) > 0 then
            open theFldr
            set the selection to msgs
(* You would modify what follows; this code will move the selected messages to a folder at the same level,
with the same name as the current folder post-fixed by a date stamp *)
            set newFldrName to name of theFldr & my FormatDate(current date)
            set newFldrName to my removeChars(newFldrName, badItemList)
            
            set newFldr to make new folder with properties {name:newFldrName}
            repeat with aMsg in msgs
                move aMsg to newFldr
            end repeat
        end if

You’d have to modify that to create your subfolders, and then move to that location.    I did not inlcude the “FormatDate” handler (subroutine) because you don’t need it for what you want to do; you might create the folder earlier, and just use the subfolder name without an appended date string.

This is just a teaser. If you want more let us know.

Oh, if you’ve never done scripting, you have to include everything inside a tell block, e.g.

Tell application “Microsoft Entourage”
--All the code except the handler
End tell
--
Add me to Palm/Visor: http://signature.coola.com/?[EMAIL PROTECTED]
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to