# Correct url of eml records

**URL:** <https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166>\
**Category:** Automation\
**Created:** [April 25, 2020, 12:18pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166 "2020-04-25T12:18:40Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sir](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@sir](https://discourse.devontechnologies.com/u/sir)\
**Post date:** [April 25, 2020, 12:18pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/1 "2020-04-25T12:18:40Z")

</div>

when dropping emails to DT manually, we get in the .elm info, a mailto:{…} URL that makes no sense to me, I want to get it to show the message callback in the form message:\{messageID}.

but something is wrong in my code and I don’t know why.  
script editor returns the correct result, but DT does not.

script editor with hardcoded string (working - please forgive the xxxx and yyyy I had to put for confidentiality):

> **set** myURL **to** “mailto:xxxx?subject=Re:%xxxxx&in-reply-to=%3Cyyyyyy@yyyyy%3E”  
> **set** mystring **to** _text item_ 2 **of** splittext(myURL, “%3C”) **as** _string_  
> **set** mystring **to** “message:%3C” & mystring  
> **display dialog** mystring  
> **on** splittext(theText, theDelimiter)  
> **set** AppleScript’s text item delimiters **to** theDelimiter  
> **set** theTextItems **to**  **every** _text item_ **of** theText  
> **set** AppleScript’s text item delimiters **to** “”  
> **return** theTextItems  
> **end** splittext

DT embedded script (not returning anything):

> **on** performSmartRule(theRecords)  
> **tell** _application_ _id_ “DNtp”  
> **repeat**  **with** theRecord **in** theRecords  
> **set** myURL **to** URL **of** theRecord **as** _string_  
> **set** mystring **to** _text item_ 2 **of** splittext(myURL, “%3C”) **as** _string_  
> **set** mystring **to** “message:%3C” & mystring  
> **display dialog** mystring  
> **end**  **repeat**  
> **end**  **tell**  
> **end** performSmartRule  
> **on** splittext(theText, theDelimiter)  
> **set** AppleScript’s text item delimiters **to** theDelimiter  
> **set** theTextItems **to**  **every** _text item_ **of** theText  
> **set** AppleScript’s text item delimiters **to** “”  
> **return** theTextItems  
> **end** splittext

this second script does not return mystring  
…anyone can help?

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [April 25, 2020, 2:28pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/2 "2020-04-25T14:28:54Z")

</div>

The URL of an imported email is a reply email address for quickly replying to it, even via the **Data \> Send Reply**.

You mean like this…

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/c/c0dbc398db810491cd86414922984c55e64aabce.jpeg)

You’re missing a **my** before calling the handler.

```auto
set mystring to text item 2 of my splittext(myURL, “%3C”) as string

```

---

<div class="post-metadata">

**Author:** ![sir](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@sir](https://discourse.devontechnologies.com/u/sir)\
**Post date:** [April 25, 2020, 10:10pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/3 "2020-04-25T22:10:31Z")

</div>

> [@BLUEFROG](#):
>
> set mystring to text item 2 of my splittext(myURL, “%3C”) as string

it works! thanks!  
just to wrap that up for anyone interested, the code below modifies the url of .eml files (in a quick & dirty way) so that they open in the default OS mail app:

```auto
on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set myURL to URL of theRecord as string
			set mystring to text item 2 of my splittext(myURL, "%3C") as string
			set mystring to "message:%3C" & mystring
			set URL of theRecord to mystring
		end repeat
	end tell
end performSmartRule

on splittext(theText, theDelimiter)
	set AppleScript's text item delimiters to theDelimiter
	set theTextItems to every text item of theText
	set AppleScript's text item delimiters to ""
	return theTextItems
end splittext

```

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [April 26, 2020, 2:12am UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/4 "2020-04-26T02:12:36Z")

</div>

You’re welcome.

PS: The email will still open in the system default email application without using this script. The difference is, in the normal state of things it opens a **reply to** email. With your modification, it opens the original email.

---

<div class="post-metadata">

**Author:** ![sir](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@sir](https://discourse.devontechnologies.com/u/sir)\
**Post date:** [April 26, 2020, 6:30am UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/5 "2020-04-26T06:30:46Z")

</div>

That’s indeed what I wanted to accomplish. For some reason the “reply to” does not show the original message. And I find that displaying the original message helps in checking the thread for replies received after clipping it to DT.  
Thanks again!

---

<div class="post-metadata">

**Author:** ![wa.k](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/wa.k/32/21927_2.png) [@wa.k](https://discourse.devontechnologies.com/u/wa.k)\
**Post date:** [May 16, 2020, 8:45am UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/6 "2020-05-16T08:45:39Z")

</div>

How can I modify “Add message(s) & attachments to DEVONthink” script to get URL of a message? Can you help me please…

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [May 18, 2020, 11:16am UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/7 "2020-05-18T11:16:30Z")

</div>

Which URL actually? Right now the email address of the sender is used by the scripts.

---

<div class="post-metadata">

**Author:** ![wa.k](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/wa.k/32/21927_2.png) [@wa.k](https://discourse.devontechnologies.com/u/wa.k)\
**Post date:** [May 18, 2020, 2:26pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/8 "2020-05-18T14:26:18Z")

</div>

Link of a message - for example “ message:%3C100423.549497696.202005071621362692877.0006168734@enews.com” instead the email address of the sender

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [May 18, 2020, 2:35pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/11 "2020-05-18T14:35:58Z")

</div>

> [@wa.k](#):
>
> Link of a message - for example “ message:%3C100423.549497696.202005071621362692877.0006168734@enews.com” instead the email address of the sender

Instead of the `sender` you would have to use `message id`:

 ![Bildschirmfoto 2020-05-18 um 16.35.49](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/3/32e985ebb252d66da1adcbf584e009731649a666.jpeg)

---

<div class="post-metadata">

**Author:** ![wa.k](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/wa.k/32/21927_2.png) [@wa.k](https://discourse.devontechnologies.com/u/wa.k)\
**Post date:** [May 18, 2020, 2:39pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/12 "2020-05-18T14:39:03Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![wa.k](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/wa.k/32/21927_2.png) [@wa.k](https://discourse.devontechnologies.com/u/wa.k)\
**Post date:** [May 18, 2020, 6:42pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/13 "2020-05-18T18:42:57Z")

</div>

it doesn’t work! I get “[20200518061432.1BBCC2A9EC3@005.de-mx.crsend.com](mailto:20200518061432.1BBCC2A9EC3@005.de-mx.crsend.com)” instead “message:%3C20200518061432.1BBCC2A9EC3@005.de-mx.crsend.com%3E”

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/2X/0/035ffa39ab31f4b6a11c42bf2a3867edf46df968.png)

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [May 18, 2020, 6:54pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/14 "2020-05-18T18:54:48Z")

</div>

1. The `message id` returned by Mail is incomplete. You would see this in the **Replies** section of the Script Editor.
2. You can’t set the URL of the file at import time _(though @cgrunenberg would have to assess if that’s correct behavior or not)_.

```auto
tell theMessage
    set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag, theID} to {the date received, the date sent, the sender, subject, the source, the read status, message id}
end tell
set msgID to "message://%3c" & theID & "%3e"
    if theSubject is equal to "" then set theSubject to pNoSubjectString
        tell application id "DNtp"
            set newRecord to (create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, source:(theSource as string), unread:(not theReadFlag)} in theGroup) -- Removed URL property
            set URL of newRecord to msgID -- Set the URL here
        end tell

```

---

<div class="post-metadata">

**Author:** ![wa.k](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/wa.k/32/21927_2.png) [@wa.k](https://discourse.devontechnologies.com/u/wa.k)\
**Post date:** [May 18, 2020, 6:57pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/15 "2020-05-18T18:57:33Z")

</div>

Thank you very much! It works))))

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [May 18, 2020, 6:58pm UTC](https://discourse.devontechnologies.com/t/correct-url-of-eml-records/55166/16 "2020-05-18T18:58:15Z")

</div>

No problem
