-- Name of the note that contains all of the subjects and allows you to navigate to them. This property is up here so that you can change it at your whim. I personally use ".email" because the period in front of it makes it appear at the top. It won't, however, show up in the Finder window because files prefixed with a "." are invisible.
property mainNoteName : ".email" -- Base name that is given to the note that contains each email. These notes are named "noteName.x.y" where noteName is the string in the following property, x is the number of the email, and y is the section number of the email. property noteName : "message" -- Name of the folder created in the "Notes" folder of your iPod. You can navigate to it just like a sub-folder by clicking "Notes"->folderName. This basically holds your emails so that they don't populate and crowd your notes folder property folderName : "Emails" -- After everything is finished, this script displays a message that tells you how many notes were created if displayInfo is set to true. If you prefer to have it run without any interaction, you can set it to false. displayQuitInterval allows you to show the message for a set period of time, if you wish. Set it to 0 to have it be displayed until you dismiss it. property displayInfo : true -- true or false. property displayQuitInterval : 30 -- integer interval in seconds -- get messages from Mail.app try tell application "Mail" check for new mail set x to "" set num_of_msgs to number of messages in inbox end tell set iPod to my getiPod () -- This section to delete the notes folder is cribbed from a portion of Apple's "Clear all Notes.scpt". Anything that uses Apple's variable naming is likely from that script. The other stuff is mine. set item_list to list folder alias ( iPod as string ) without invisibles if item_list contains "Notes" then tell application "Finder" set notesFolder to ( folder "Notes" of iPod ) set item_list to list folder alias ( notesFolder as string ) if item_list contains folderName then delete item folderName of notesFolder end if make new folder at folder "Notes" of disk iPod with properties { name : folderName } set emailFolder to folder folderName of folder "Notes" of disk iPod end tell end if repeat with i from 1 to num_of_msgs -- unread count of inbox set x to my getMessageFromMail ( i ) -- Break up text into 4k segments. iPod only holds text notes up to 4k in size set msg_segments to round (( length of x ) / 4000) rounding up set bytes_left to length of x repeat with j from 1 to msg_segments -- If the text needs to be broken up, write 3,950 each time until below the 4k limit, then write the remainder if bytes_left > 4000 then set bytes_to_read to 3950 set bytes_left to bytes_left - 3950 -- If the message is less than 4k, only write the amount of the " & noteName & "." else set bytes_to_read to length of x end if set msg to "" set msg to ( characters 1 through bytes_to_read of x ) as string -- Leave note to navigate to next message if j is equal to msg_segments then -- End of current message if i is less than num_of_msgs then set msg to ( msg & return & return & "[<a href=\"" & noteName & "." & ( i + 1) as string ) & ".1\">NEXT MESSAGE</a>]" end if else -- Message continued -- Leave a link to navigate to the next part of the message set msg to (( msg & return & return & "[<a href=\"" & noteName & "." & i as string ) & "." & ( j + 1) as string ) & "\">NEXT PORTION OF MESSAGE</a>]" end if -- Link to the index page set msg to msg & return & "[<a href=\"" & mainNoteName & "\">MAIN</a>]" set target_file to ( emailFolder as string ) & "" & noteName & "." & ( i as string ) & "." & ( j as string ) my writeToFile ( msg , target_file ) end repeat end repeat set target_file to ( emailFolder as string ) & mainNoteName my writeToFile ( my createMainPage (), target_file ) if displayInfo then if displayQuitInterval is 0 then display dialog ("Mail to iPod" & return & return & ( num_of_msgs as string ) & " notes were created.") buttons {"Gee, thanks"} default button 1 else display dialog ("Mail to iPod" & return & return & ( num_of_msgs as string ) & " notes were created.") buttons {"Gee, thanks"} default button 1 giving up after displayQuitInterval end if end if end try on getMessageFromMail ( indx ) tell application "Mail" set msg to ( content of message indx of inbox ) as string set ttl to ( subject of message indx of inbox ) as string set nme to ( sender of message indx of inbox ) as string end tell return "E-mail from " & nme & ":" & return & ttl & return & msg end getMessageFromMail on writeToFile ( msg_data , target_file ) try set open_file to open for access file target_file with write permission set eof of open_file to 0 write msg_data to open_file starting at eof close access open_file end try end writeToFile on createMainPage () tell application "Mail" set titles to "" repeat with i from 1 to number of messages in inbox -- unread count of inbox set titles to (( titles & return & "[<a href=\"" & noteName & "." & i as string ) & ".1\">" & subject of message i of inbox as string ) & "</a>]" end repeat set txt to "Number of new messages " & number of messages in inbox -- unread count of inbox set txt to txt & return & return & titles end tell return txt end createMainPage on getiPod () -- stolen shamelessly from Apple's "Clipboard to Note.scpt" set the volumes_directory to "/Volumes/" as POSIX file as alias set the volume_names to list folder volumes_directory without invisibles set mounted_iPods to {} repeat with i from 1 to the count of volume_names try set this_name to item i of volume_names set this_disk to ("/Volumes/" & this_name & "/") as POSIX file as alias set these_items to list folder this_disk if "iPod_Control" is in these_items then set the end of the mounted_iPods to this_disk end if end try end repeat return item 1 of mounted_iPods end getiPod