Here is Version 16. The major change is that part of the message
text can now be added to Comments. To make it easier for the user to
get at the statement where the number of characters added is set, I
have moved all the function routines to the end of the script.
Script follows next line
_________________________________________________________
(* Script to pipe selected Apple Mail messages to Yojimbo notes
Version 16
2007/04/12
This script will:
1. Pipe selected selected messages from Apple Mail to Yojimbo notes.
2. Put the date sent (yyyy/mm/dd) & name or address of sender or
recipient into Comments.
3. Add the first 60 characters (user changeable) of the message to
Comments after removing returns, tabs, and most extra spaces.
4. Add tags "email" and either "in" or "out" to each note.
After running the script, a Comment will look something like:
"2007/04/08 <: NYTimes.com________Your subscription is up soon.
Please ren" (an incoming message)
or
"2007/04/09 >: Sam________I can't believe that you won the
lottery" (an outgoing message)
Notes:
1) A message is classified as outgoing if the sender's address
matches one of the user's addresses. If an account has been deleted,
there is no address to match, and all messages are classified as
incoming. To fix this behavior, create and inactivate a dummy
account. Only the email address must be correct; the other settings
are irrelevant.
2) As the notes are text, graphics do not display, but they sometimes
show as "?".
3) One space will be left for every return or new line.
4) You can reset he number of characters that are added from the
body of the message (_maxcontent). The setting statement appears just
after the "on run" command at the start of the script.
Credits:
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
The error dialog was copied from MailToYojimbo-v1.1 by Drummond
Field, posted at
http://www.hawkwings.net/2007/02/05/email-to-yojimbo-script-with-pdf-
support
The source for the minimum function was: http://www.macresearch.org/
no_need_to_parse_an_expression
The form for the shell script & Perl commands were guessed from
http://developer.apple.com/technotes/tn2002/tn2065.html
http://developer.apple.com/documentation/OpenSource/Conceptual/
ShellScripting/RegularExpressionsUnfettered/chapter_6_section_9.html
Steve Samuels
[EMAIL PROTECTED]
*)
on run
--SPECIFY HOW HOW MUCH OF THE MESSAGE TO ADD COMMENTS. IF YOU WANT
NONE, CHANGE THE VALUE BELOW TO ZERO.
--IF YOU DON'T WANT ANY, SET THE LENGTH TO 0
set _maxcontent to 60 as integer
tell application "Yojimbo"
activate
end tell
tell application "Mail"
activate
if not (exists message viewer 1) then
display dialog "No Viewer Window is Open. Open one & select
messages." & return with title "Error...." giving up after 3 with icon 0
return
end if
tell message viewer 1
set messageList to selected messages
if not (exists selected messages) then
display dialog "No message was selected" & return & "Transfer
cancelled." with title "Error..." giving up after 3 with icon 0
return
end if
--Now loop through messages
repeat with m in messageList
--Initialize
set _type to ""
set _contents to ""
set _name to ""
set _person to ""
set _tag to ""
set _body to ""
--Classify message as incoming or outgoing
set _count to my CountSent(m) as integer
if _count is 1 then
set _type to "outgoing"
else
set _type to "incoming"
end if
set _name to subject of m
set _contents to _contents & my generateMessageText(m)
--Set up date sent
set _date to date sent of m
set _yr to year of _date as string
set _month to month of _date as number
--Force month to format 'mm'
set _smon to _month as string
if _month < 10 then
set _smon to "0" & _smon
end if
--Force day to format 'dd'
set _day to day of _date as string
if day of _date < 10 then
set _day to "0" & _day
end if
-- Create date sent with yyyy/mm/dd format
set _datef to _yr & "/" & _smon & "/" & _day
--Get sender's name or address
set _sender to extract name from sender of m
--If there is no name, _sender defaults to the address
--If the message was received, set the name to the sender
-- and set a tag variable to "in"
if _type is "incoming" then
set _person to "<: " & _sender
set _tag to "in" as string
end if
--If the message was sent, get the first recipient's name, if
available, otherwise the address
if _type is "outgoing" then
set theRecipients to to recipients of m
if (exists name of item 1 of theRecipients) then
set _person to ">: " & name of item 1 of theRecipients
else
set _person to ">: " & address of item 1 of theRecipients
end if
set _tag to "out" as string
end if
--now get the first 60 characters of the message content or the whole
if fewer than 60
set _body to ""
set _body to _body & my genbody(m) as text
set _length to length of _body
if _maxcontent is 0 then
set _shorttext to "." as text
else
set _allow to my min(_length, _maxcontent + 20)
--Reduce the burden on the shell script by allowing for spaces &
returns that will be removed.
set _toomuch to get text 1 thru _allow of _body
--WARNING: DO NOT ATTEMPT TO JOIN THE FOLLOWING LINES. THEY-- CONTAIN
HIDDEN TAB RETURN CHARACTERS
set _text1 to do shell script "echo " & quoted form of _toomuch & " |
perl -e \"while(\\$line = <STDIN>) { \\$line =~ s/[
]+/ /g; print \\$line; }\""
--Now find the maximum length of the content to be added
set _lengthnow to length of _text1
set _most to my min(_lengthnow, _maxcontent)
set _shorttext to get text 1 through _most of _text1
set _shorttext to "______" & _shorttext
end if
---Now set up the note with body, comments, and tags.
tell application "Yojimbo"
set aNewNoteItem to make new note item with properties
{contents:_contents, name:_name, comments:_datef & " " & _person &
_shorttext}
add tags {"email", _tag} to aNewNoteItem
end tell
end repeat
end tell
end tell
end run
-- Function routines follow
on genbody(m)
tell application "Mail"
set _contents to content of m
return _contents
end tell
end genbody
--Set up a function to generate the body of the message (from Jim
Correia)
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
--Set up a second function to pass a variable which indicates whether
I sent the message or not
--
on CountSent(m)
tell application "Mail"
set _saddr to extract address from sender of m
set _ctsent to 0 as integer
repeat with _acct in accounts
if email addresses of _acct contains _saddr then
set _ctsent to _ctsent + 1 as integer
-- _ctsent counts the number of times the sender's address matches
one of mine
-- At the end of the function, the value of _ctsent will be 0 or 1
end if
end repeat
end tell
return _ctsent
end CountSent
--define minimum function for adding message content to comments
--Source: http://www.macresearch.org/no_need_to_parse_an_expression
on min(x, y)
if (x ≤ y) then
return x
else
return y
end if
end min
--
------------------------------------------------------------------
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]>