Here's an improved version of the script I just sent. This version doesn't require any manual entries by the user. The only ambiguity I see (I'm sure there are more) is that if you send an email to a mailing list which then receive it as a member of the list, it will be classified as sent not received.

Steve

(* Script to
1. pipe a single selected email message from Apple Mail to a Yojimbo note 2. Add to comments: date sent (yyyy/mm/dd), day of week sent ,recipient or sender
3. Add tags "email" and either "in" or "out" to the entry

Acknowledgement: Based on MailtoYojimbo Applescript by Jim Correia of Bare Bones Software Originally posted in the Yojimbo Talk Forum: http://www.listsearch.com/Yojimbo/Message/index.lasso?2169 Also at://www.hawkwings.net/2006/09/04/script-to-pipe-emails-into- yojimbo/

   Steve Samuels
*)

on generateMessageText(m)
tell application "Mail"
set _sender to sender of m
set _subject to subject of m
set _date to date received of m as string
set _contents to content of m
set _messageString to "From: " & _sender & return
set _messageString to _messageString & "Subject: " & _subject & return
set _messageString to _messageString & "Date: " & _date & return
set _messageString to _messageString & return & return & _contents
end tell

end generateMessageText

on run
tell application "Mail"
tell message viewer 1
set messageList to selected messages
set _name to subject of item 1 of messageList
set _contents to ""

--Get content
repeat with m in messageList
set _contents to _contents & my generateMessageText(m)
end repeat

--Get date sent
set _date to date sent of item 1 of messageList
set _yr to year of _date as string
set _month to month of _date
-- Coerce month to number
set _month to _month + 0
set _smon to _month as string
if _month < 10 then
set _smon to "0" & _month
end if

set _day to day of _date as string
if day of _date < 10 then
set _day to "0" & _day
end if
-- Create date with yyyy/mm/dd format
set _ldate to _yr & "/" & _smon & "/" & _day & " "

--Get sender
set _sender to sender of item 1 of messageList
set _ssender to extract name from _sender
set _person to "<:" & _ssender

--Check if sender is me.
set _from_me to false
set _saddr to extract address from _sender

end tell

--Find if the sender matches one of my email addresses
repeat with _acct in accounts
if email addresses of _acct contains _saddr then
set _from_me to true
end if
end repeat
_from_me

-- If message was received, set up note with tags "mail" & "in".
if _from_me is false then
tell application "Yojimbo"
set aNewNoteItem to make new note item with properties {contents:_contents, name:_name, comments:_ldate & _person}
add tags {"email", "in"} to aNewNoteItem
end tell

--If mail was sent, get first recipient. If there is no name, use the address.
else
set theRecipients to to recipients of item 1 of messageList
if (exists name of item 1 of theRecipients) then
set _pers to name of item 1 of theRecipients
set _person to ">:" & _pers
else
set _addr to address of item 1 of theRecipients
set _person to ">:" & _addr
end if
-- Set up note with tags "mail" & "out"
tell application "Yojimbo"
set aNewNoteItem to make new note item with properties {contents:_contents, name:_name, comments:_ldate & _person}
add tags {"email", "out"} to aNewNoteItem
end tell
end if
end tell
end run

--
------------------------------------------------------------------
This message is sent to you because you are subscribed to
 the mailing list <[email protected]>.
To unsubscribe, send mail to: <[EMAIL PROTECTED]>
List archives:  <http://www.listsearch.com/yojimbotalk.lasso>
Have a feature request, or not sure if the software's working correctly? Please send mail to: <[EMAIL PROTECTED]>

Reply via email to