• 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: Getting text out of Mail headers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting text out of Mail headers


  • Subject: Re: Getting text out of Mail headers
  • From: "@lbutlr via AppleScript-Users" <email@hidden>
  • Date: Tue, 9 Jun 2020 16:51:02 -0600

On 09 Jun 2020, at 12:54, LuKreme via AppleScript-Users
<email@hidden <mailto:email@hidden>>
wrote:
> Interesting. How does that deal with Received headers where there are
> multiples in each email?

Ah, the answer is "poorly" 😃

Header 1 returns the first matching header, header 2 the second matching
header. Every header returns, as one might expect, every matching header. If
there is a syntax for

every header whose name is "received" and contains "ESMTPS id" and whose text
contains "by mail.myserver.tld"

I haven't figured it out yet.

This will, at the very least, be entertaining!

This works perfectly, but is not what I am after:


tell application id "com.apple.mail" -- Mail.app
        set myMessage to item 1 of (get selection)
        set myID to content of header 1 of myMessage whose name is "message-id"
        return "message:" & myID -- Retrun message URL
end tell

Super useful though, going to integrate that into Typinator

message:<email@hidden>
<message:<email@hidden>>

I supposed I need to convert the < and > to < >

use framework "Foundation"

tell application id "com.apple.mail" -- Mail.app
        set myMessage to item 1 of (get selection)
        set myID to content of every header of myMessage whose name is
"message-id"
end tell
return urlEncode("message:" & myID)

on urlEncode(input)
        tell current application's NSString to set rawUrl to
stringWithString_(input)
        set theEncodedURL to rawUrl's
stringByAddingPercentEscapesUsingEncoding:4
        return theEncodedURL as Unicode text
end urlEncode

This works, but is very slow. For this case it is probably faster and simpler
to just replace the two characters.

on urlEncode(inText)
        set outText to ""
        repeat with eachChar in characters of inText
                set tmpChar to eachChar
                set charNum to ASCII number of eachChar
                if (ASCII number of eachChar) = 60 then set tmpChar to "<"
                if (ASCII number of eachChar) = 62 then set tmpChar to ">"
                set outText to outText & tmpChar as string
        end repeat
        return outText
end urlEncode

Typinator output looks like this:

In reply to:
message:

Rabbit hole? Me? Now, I guess I'll get back to what I was actually trying to do.



--
ARE YOU FAMILIAR WITH THE WORDS 'DEATH WAS HIS CONSTANT COMPANION'?
        'But I don't usually see you!'


 _______________________________________________
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

  • Follow-Ups:
    • Re: Getting text out of Mail headers
      • From: Shane Stanley via AppleScript-Users <email@hidden>
References: 
 >Re: Getting text out of Mail headers (From: Shane Stanley via AppleScript-Users <email@hidden>)
 >Re: Getting text out of Mail headers (From: LuKreme via AppleScript-Users <email@hidden>)

  • Prev by Date: Re: Getting text out of Mail headers
  • Next by Date: Re: Getting text out of Mail headers
  • Previous by thread: Re: Getting text out of Mail headers
  • Next by thread: Re: Getting text out of Mail headers
  • Index(es):
    • Date
    • Thread