Mailsmith
Other Programs
Scripts
Mailsmith.scpt
Archive to sub-mailbox
Check Spelling
Find reply
Change font size
Submit Script to JEM
Fix common spelling errors
Setting SMTP server
URL from Safari
Address from AB
linkMunge
Export to Address Book
Saving attachments
Digest Script
File with same
POP window position
Position of new windows
iCal and Mailsmith
Edit From Line
Modified Thread Script
Reply to Selection
Temporary Text Window
Compact gain
Tracking backups
Edit subject
Googler
Auto-rewrap
MMA
SMTP server
Open, fetch, and close
URL Manager
BrainForest
Thread by Author
Thread by subject
Export Email
Get Selection
Read Addresses
Export Email
Organize Email
Account setup
Mailsmith 2 BBEdit
BBEdit 2 Mailsmith
Search II
Check One
Delete Enclosure
Open, fetch, close
Set Answered
Set Redirected
Empty Trash
List found
Print Several
Del. old. msg.
Delete Enclosures
Accounts
Address Book
Editing
Filters
General
Import/Export
Links
Mailboxes
Memory
Scripting
Speed
send/receive
Tips/Tricks


Getting Selected Messages

Author Jan Erik Moström
Last modified 2000-08-13
What is this?

Description
This script is intended as part of a larger script. The interesting part is the buildMessageList handler (the rest is just a demonstration of how it can be used). The handlers checks what messages you have selected and returns a list of selected the messages.

You can can select one or more mailboxes or one or more messages (either by selecting them or selecting some text of one message). If no messages is selected the value "false" is returned, to determine if some messages were selected or something else (like an email address) check the class of the returned value.

The handler is based on a handler posted by BBSW


on buildMessageList()
    tell application "Mailsmith 1.1"
        set xs to (the selection) as list
        try
            set cName to class of (item 1 of xs)
        on error
            return false
        end try
        set msgList to {}
        if cName is mailbox then
            repeat with i in xs
                set msgList to msgList & every message of i
            end repeat
        else if cName is string then
            set msgList to {message of window 1}
        else if cName is message then
            set msgList to xs
        else
            return false
        end if
        return {msgList:msgList}
    end tell
end buildMessageList


-- An example of how buildMessageList can be used
on run
    tell application "Mailsmith 1.1"
        set messageList to my buildMessageList()
        if class of messageList is list then
            -- write a file with the subject of each message
            set nf to new file with prompt "Choose output file"
            set wf to open for access nf with write permission
            repeat with curMsg in messageList
                set curHead to subject of curMsg
                write curHead & return to wf
            end repeat
            close access wf
        else
            display dialog "Sorry, no messages were selected"
        end if
    end tell
    display dialog "The subject of " & the number of items of messageList & " messages have been written to the file"
end run