Hi Alastair,
I see you're still struggling with your email ingest program. I looked at it a while ago and would like to make some suggestions.
1. Separation of applications I don't know how you handle the transfer from Mail to theText, but I would suggest something like tell application "Mail" try # initialise lists set website_emails to {} set mailout_emails to {} set other_emails to {} set email_selection to (get selection) # loop thru all selected email messages and sort into three groups repeat with a_msg in email_selection # Determine if source is website or email set email_subject to subject of a_msg if email_subject starts with "Enquiry from Website" then copy content of a_msg to the end of website_emails log ("Website: " & email_subject) else if email_subject starts with "Subscribe Foo Bar" then copy content of a_msg to the end of mailout_emails log ("TP Mailout: " & email_subject) else copy content of a_msg to the end of other_emails end if end repeat on error the error_message number the error_number display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1 end try end tell
which leaves you with the text of the messages in the different lists, you don't have anything to do with Mail after that.
2. Structure of Excel sheet Some of your troubles stem from the transfer of the email contents into columns in Excel. You don't need to change your lists into lists of lists if you use the clipboard: tell application "Microsoft Excel" set index to 50 repeat with myMessage in website_emails set the clipboard to myMessage paste special range "A" & index of from_tp_website what value # need only the start cell set index to index + 1 end repeat end tell This will paste the text from your clipboard into the following cells, taking a tab as next cell in a row and a return as next row. In any case you may need to check that there are no more than 50 lines of text. Actually I would try to work with rows and give each entry a new row, for that you would have to change the returns into tabs in the text, and you could leave them as long as you want (Excel allows 16.384 columns).
3. For your current question, line breaks (line feed = LF) are URL-encoded as
, while return (carriage return = CR) is
, so the internet standard for a line break (LFCR) is
and usually handled transparently by Mac applications, "0D
%" wouldn't do. You can set AppleScript's text item delimiters to {"
"} and then use the text items to populate a list if the text break doesn't work otherwise.
Hope this helps, come back if you have more questions.
Best Thomas Am 26.03.2014 um 03:39 schrieb Alastair Leith: I have some line breaks hiding from me in email contents and presumably I need to change text delimiters to flush them out but not sure what I can set text delimiters to to do it. It's caused by me using "0D
%" for some line breaks in the email form I generate with an HTML "mailto:" command instead of "0D
" The later seem to register inside Apple Script as a line break but the former do not.
This is how I process other emails coming from the website form and it all works fine: set pasteText to (paragraphs from paragraph n to the last paragraph) of theText -- not splitting paras at soft line breaks -- Then I parse into an Excel friendly format with:
repeat with p in pasteText set cellText's end to {p's contents} end repeat repeat 50 - (count cellText) times set cellText's end to {""} end repeat set r to "A1:A" & (count cellText)
Another set of emails are reply emails from an HTML mailout I send. I create a blank form in the email using an HTML mailto: statement as follows
People click the link and then fill-out the email form. But only the first line break of the form registers in Script Debugger as a \n line break. If you examine the variable in it's own window it all looks normal but when it is compressed to a single line item in the variables tab it's evident some line breaks are registering (0D
) as "\n" and the others are not breaking at all (0D
%). I can fix the HTML in the next mailout I do but is there any way I can find these pesky line breaks in the 50 or so emails I need to process?
Presumably it involves setting text delimiters to something else but not sure what that something else is
|