• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Searching a Mail message
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Searching a Mail message


  • Subject: Re: Searching a Mail message
  • From: Philip Aker <email@hidden>
  • Date: Sun, 3 Jun 2007 22:24:30 -0700

On 2007-06-03, at 18:21:21, deivy petrescu wrote:


On Jun 3, 2007, at 10:32, Philip Aker wrote:

On 2007-06-03, at 07:21:50, deivy petrescu wrote:

Some people tend to undermine AS abilities.
May be my problem is I tend to overestimate its capabilities and can not go past it.

Here's your script adapted to work with Mail. When I run it on your post I'm replying to, it doesn't produce an acceptable result.


Philip,
I beg to disagree. It produces perfect results.

You're kidding right?

Certainly not!

Deivy,

I'll restate the problem: "The object is to get valid email addresses from the content of an email message." What happens is that if one has Mail set up to accept HTML mail, then all bets are off. That's because Mail uses a WebView and not an NSTextView. The problem is getting 'content of' to work the same as if one had manually clicked in the received email area, then done "Select All", then "Copy", and then worked on 'the clipboard as text'.

tell application "Mail" to content of item 1 of (get selection)

does not return the same result as Select All/Copy in all cases.

So new improved formula or not, the solution has not been found.

Philip


Reread my message. I said I cheated a bit.

Yes, you admitted you cheated. The object is to get valid email addresses from the content of an email message. So your code getting them from a fixed text item doesn't solve much. See my reply to Doug MacNutt for an alternate. Leaving the solution as an exercise is not proof of viability.


Philip,


Actually, your answer to Doug jut proves my case. This, my cheap way, got all email addresses, which, you did not do with you "better" way.


The only problem I've left out on the first script was that hard returns and no space make it for another word.
This is not particularly difficult to get rid of.


However, the problem of getting only correct email addresses requires more work on the part of the o.p. and it depends on the habits of the people who write.
As I said, "meet email@hidden is great" is kind of hard to decide is not an email address.
Also "email@hidden" will include the " at the beginning and at the end. So write a script to remove all spurious symbols.


Here is the homework you did not wanted to do (includes getting the text from the current mail message)

<script>
tell application "Mail" to set m to content of item 1 of (get selection)


set m to change {m, ASCII character 10, space}

tid("@")
set emails to {}
set q to text items of m
tid(space)
repeat with j from 1 to ((count q) - 1)
if (text item -1 of text item j of q) ≠ "" and (text item 1 of text item (j + 1) of q) ≠ "" then set end of emails to (text item -1 of text item j of q) & "@" & (text item 1 of text item (j + 1) of q)
end repeat


tid("")

emails

on tid(x)
	set AppleScript's text item delimiters to x
end tid


on change {texto, x, y} tid(x) set texto to text items of texto tid(y) return texto as Unicode text end change <script>

Which returned using your reply:
--{"me@3PM\"", "tid(\"@\")", "\"@\"", "{\"\\\"@\\\"\",", "tid(\\\"@\ \\")", "\"\\\"email@hidden\",", "\"email@hidden\",", "\"email@hidden\",", "\"\\ \"@\\\"\",", "---{\\\"email@hidden\\\",\",", "\"\\ \"email@hidden\\\",\",", "\"\\\"email@hidden\\ \"}", "\"(email@hidden)", "\"email@hidden", "(email@hidden)", "email@hidden"}



Now as another hw, I'll ask people to remove the \", ), (, etc. from each email.
Ah! All the email addresses are there. Check.



Deivy _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript- email@hidden)
Help/Unsubscribe/Update your Subscription:
@mac.com
Archives: http://lists.apple.com/archives/applescript-users


This email sent to email@hidden



Philip Aker email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Re: Searching a Mail message (From: Jeffers <email@hidden>)
 >Re: Searching a Mail message (From: Luther Fuller <email@hidden>)
 >Re: Searching a Mail message (From: Michelle Steiner <email@hidden>)
 >Re: Searching a Mail message (From: Luther Fuller <email@hidden>)
 >Re: Searching a Mail message (From: Michelle Steiner <email@hidden>)
 >Re: Searching a Mail message (From: Luther Fuller <email@hidden>)
 >Re: Searching a Mail message (From: deivy petrescu <email@hidden>)
 >Re: Searching a Mail message (From: Philip Aker <email@hidden>)
 >Re: Searching a Mail message (From: deivy petrescu <email@hidden>)
 >Re: Searching a Mail message (From: Philip Aker <email@hidden>)
 >Re: Searching a Mail message (From: deivy petrescu <email@hidden>)

  • Prev by Date: Re: Searching a Mail message
  • Next by Date: resetting script between runs
  • Previous by thread: Re: Searching a Mail message
  • Next by thread: Re: Searching a Mail message
  • Index(es):
    • Date
    • Thread