emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* PATCH: Fix malformed "message" links produced by org-mac-link.el
@ 2014-09-24 10:39 Steve Purcell
  2014-09-24 15:35 ` Alan Schmitt
  0 siblings, 1 reply; 9+ messages in thread
From: Steve Purcell @ 2014-09-24 10:39 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 373 bytes --]

Links which should look like:

[[message://2.11f23692084eb783e40c@NY-WEB01][Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchange]]

are currently mangled into:

[[essage://2.11f23692084eb783e40c@NY-WEB01][Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchang]]

This tiny patch fixes this issue.

Tested on OS X 10.9.

-Steve


[-- Attachment #2: 0001-org-mac-link.el-Fix-malformed-message-links.patch --]
[-- Type: application/octet-stream, Size: 2311 bytes --]

From 6689b708ddc2e9f9bedfe6c0c2ef5f3084bf1ac6 Mon Sep 17 00:00:00 2001
From: Steve Purcell <steve@sanityinc.com>
Date: Wed, 24 Sep 2014 11:27:00 +0100
Subject: [PATCH] org-mac-link.el: Fix malformed message links

* contrib/lisp/org-mac-link.el (org-mac-message-get-links): Use the `org-mac-paste-applescript-links' helper.

The existing code inserted links which should have been "[[message:ABC][the subject]]"
as "[[essage:ABC][the subjec]]".

TINYCHANGE
---
 contrib/lisp/org-mac-link.el | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/contrib/lisp/org-mac-link.el b/contrib/lisp/org-mac-link.el
index 3b58d04..3389334 100644
--- a/contrib/lisp/org-mac-link.el
+++ b/contrib/lisp/org-mac-link.el
@@ -856,27 +856,11 @@ The Org-syntax text will be pushed to the kill ring, and also returned."
   (interactive "sLink to (s)elected or (f)lagged messages: ")
   (setq select-or-flag (or select-or-flag "s"))
   (message "AppleScript: searching mailboxes...")
-  (let* ((as-link-list
-          (if (string= select-or-flag "s")
-              (org-as-get-selected-mail)
-	    (if (string= select-or-flag "f")
-		(org-as-get-flagged-mail)
-	      (error "Please select \"s\" or \"f\""))))
-         (link-list
-          (mapcar
-           (lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x) (setq x (match-string 1 x))) x)
-           (split-string (substring as-link-list 1 -1) "[\r\n]+")))
-         split-link URL description orglink orglink-insert rtn orglink-list)
-    (while link-list
-      (setq split-link (split-string (pop link-list) "::split::"))
-      (setq URL (car split-link))
-      (setq description (cadr split-link))
-      (when (not (string= URL ""))
-        (setq orglink (org-make-link-string URL description))
-        (push orglink orglink-list)))
-    (setq rtn (mapconcat 'identity orglink-list "\n"))
-    (kill-new rtn)
-    rtn))
+  (org-mac-paste-applescript-links
+   (cond
+    ((string= select-or-flag "s") (org-as-get-selected-mail))
+    ((string= select-or-flag "f") (org-as-get-flagged-mail))
+    (t (error "Please select \"s\" or \"f\"")))))
 
 (defun org-mac-message-insert-selected ()
   "Insert a link to the messages currently selected in Mail.app.
-- 
2.1.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-09-24 10:39 PATCH: Fix malformed "message" links produced by org-mac-link.el Steve Purcell
@ 2014-09-24 15:35 ` Alan Schmitt
  2014-09-24 15:42   ` Steve Purcell
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Schmitt @ 2014-09-24 15:35 UTC (permalink / raw)
  To: Steve Purcell; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 651 bytes --]

On 2014-09-24 11:39, Steve Purcell <steve@sanityinc.com> writes:

> Links which should look like:
>
> [[message://2.11f23692084eb783e40c@NY-WEB01][Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchange]]
>
> are currently mangled into:
>
> [[essage://2.11f23692084eb783e40c@NY-WEB01][Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchang]]
>
> This tiny patch fixes this issue.

I just tested it with the current version and I'm not seeing this
problem. Is there something special about that email that breaks, or are
you seeing problems with every email?

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-09-24 15:35 ` Alan Schmitt
@ 2014-09-24 15:42   ` Steve Purcell
  2014-09-24 19:01     ` Alan Schmitt
  0 siblings, 1 reply; 9+ messages in thread
From: Steve Purcell @ 2014-09-24 15:42 UTC (permalink / raw)
  To: emacs-orgmode

Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> I just tested it with the current version and I'm not seeing this
> problem. Is there something special about that email that breaks, or are
> you seeing problems with every email?

I see it with every mail. I'm on OS X 10.9.5, but the problem was also
present on 10.9.4.

The "substring" part of the removed code led to the trimming of the
characters at each end, so it's not clear to me how it could ever have
worked, unless the output is routinely wrapped in quotes on others'
machines.

Mysterious indeed.

In any case, there were a few blocks of identical-looking code dotted
around the file: the block appears to have been wisely extracted into
org-mac-paste-applescript-links, but the duplicate code hasn't been
replaced with a call to that function. So this patch does so for the
Mail case, and the same fix should also probably be made in
org-mac-outlook-message-get-links.

-Steve

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-09-24 15:42   ` Steve Purcell
@ 2014-09-24 19:01     ` Alan Schmitt
  2014-09-24 19:56       ` Steve Purcell
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Schmitt @ 2014-09-24 19:01 UTC (permalink / raw)
  To: Steve Purcell; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2167 bytes --]

On 2014-09-24 16:42, Steve Purcell <steve@sanityinc.com> writes:

> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>> I just tested it with the current version and I'm not seeing this
>> problem. Is there something special about that email that breaks, or are
>> you seeing problems with every email?
>
> I see it with every mail. I'm on OS X 10.9.5, but the problem was also
> present on 10.9.4.

I'm also on 10.9.5. I was probably on 10.9.4 when I tweaked that code.

> The "substring" part of the removed code led to the trimming of the
> characters at each end, so it's not clear to me how it could ever have
> worked, unless the output is routinely wrapped in quotes on others'
> machines.

This was the case here: the string returned by the AppleScript had
quotes (and it still does).

For instance, with the message you mention, the call to
org-as-get-selected-mail returns this (doing a debug):

Result: "\"message://2.b2af716655bbac583727@NY-WEB01::split::Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchange\""

> Mysterious indeed.
>
> In any case, there were a few blocks of identical-looking code dotted
> around the file: the block appears to have been wisely extracted into
> org-mac-paste-applescript-links, but the duplicate code hasn't been
> replaced with a call to that function. So this patch does so for the
> Mail case, and the same fix should also probably be made in
> org-mac-outlook-message-get-links.

It works well for grabbing a single message, but it breaks when grabbing
several. Here is one such broken result:

[[message://9670A832-D0B3-46A8-96BF-05C30D85085D@gmail.com][Re: De passage ˆ San Jose"]]
[["message://4B980C40-DB9A-47A7-95A7-17BB8CF8167F@gmail.com][Re: De passage ˆ San Jose]]

The string returned by the AppleScript was this:

Result: "\"message://4B980C40-DB9A-47A7-95A7-17BB8CF8167F@gmail.com::split::Re: De passage \210 San Jose\nmessage://9670A832-D0B3-46A8-96BF-05C30D85085D@gmail.com::split::Re: De passage \210 San Jose\""

Does it work on your machine with several messages selected?

Best,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-09-24 19:01     ` Alan Schmitt
@ 2014-09-24 19:56       ` Steve Purcell
  2014-09-25  6:14         ` Alan Schmitt
  0 siblings, 1 reply; 9+ messages in thread
From: Steve Purcell @ 2014-09-24 19:56 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

On 24 Sep 2014, at 20:01, Alan Schmitt <alan.schmitt@polytechnique.org> wrote:

> This was the case here: the string returned by the AppleScript had
> quotes (and it still does).
> 
> For instance, with the message you mention, the call to
> org-as-get-selected-mail returns this (doing a debug):
> 
> Result: "\"message://2.b2af716655bbac583727@NY-WEB01::split::Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchange\””


I definitely don’t get quotes in the result of org-as-get-selected-mail.


> It works well for grabbing a single message, but it breaks when grabbing
> several. Here is one such broken result:
> 
> [[message://9670A832-D0B3-46A8-96BF-05C30D85085D@gmail.com][Re: De passage ˆ San Jose"]]
> [["message://4B980C40-DB9A-47A7-95A7-17BB8CF8167F@gmail.com][Re: De passage ˆ San Jose]]
> 
> The string returned by the AppleScript was this:
> 
> Result: "\"message://4B980C40-DB9A-47A7-95A7-17BB8CF8167F@gmail.com::split::Re: De passage \210 San Jose\nmessage://9670A832-D0B3-46A8-96BF-05C30D85085D@gmail.com::split::Re: De passage \210 San Jose\""
> 
> Does it work on your machine with several messages selected?


Yes, it works correctly, as in the following links to this mail thread:


[[message://m2h9zwzvuz.fsf@polytechnique.org][Re: {O} PATCH: Fix malformed "message" links produced by org-mac-link.el]]
[[message://m28ul9vxnr.fsf@top.irisa.fr][Re: {O} PATCH: Fix malformed "message" links produced by org-mac-link.el]]


Not sure how to proceed, then…

-Steve

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-09-24 19:56       ` Steve Purcell
@ 2014-09-25  6:14         ` Alan Schmitt
  2014-10-09 12:15           ` Alan Schmitt
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Schmitt @ 2014-09-25  6:14 UTC (permalink / raw)
  To: Steve Purcell; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 954 bytes --]

On 2014-09-24 20:56, Steve Purcell <steve@sanityinc.com> writes:

> On 24 Sep 2014, at 20:01, Alan Schmitt <alan.schmitt@polytechnique.org> wrote:
>
>> This was the case here: the string returned by the AppleScript had
>> quotes (and it still does).
>> 
>> For instance, with the message you mention, the call to
>> org-as-get-selected-mail returns this (doing a debug):
>> 
>> Result: "\"message://2.b2af716655bbac583727@NY-WEB01::split::Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchange\””
>
>
> I definitely don’t get quotes in the result of org-as-get-selected-mail.
> Not sure how to proceed, then…

It seems that the difference is with getting quotes or not. How about
changing org-as-get-selected-mail to make sure there is no quote? We
could for instance test whether the first and last characters are
quotes, and remove them if they are.

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-09-25  6:14         ` Alan Schmitt
@ 2014-10-09 12:15           ` Alan Schmitt
  2014-10-09 12:25             ` Steve Purcell
  0 siblings, 1 reply; 9+ messages in thread
From: Alan Schmitt @ 2014-10-09 12:15 UTC (permalink / raw)
  To: Steve Purcell; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1065 bytes --]

Hello Steve,

On 2014-09-25 08:14, Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> On 2014-09-24 20:56, Steve Purcell <steve@sanityinc.com> writes:
>
>> On 24 Sep 2014, at 20:01, Alan Schmitt <alan.schmitt@polytechnique.org> wrote:
>>
>>> This was the case here: the string returned by the AppleScript had
>>> quotes (and it still does).
>>> 
>>> For instance, with the message you mention, the call to
>>> org-as-get-selected-mail returns this (doing a debug):
>>> 
>>> Result: "\"message://2.b2af716655bbac583727@NY-WEB01::split::Private beta invitation for Emacs Q&A site - Area 51 - Stack Exchange\””
>>
>>
>> I definitely don’t get quotes in the result of org-as-get-selected-mail.
>
> …
>
>> Not sure how to proceed, then…
>
> It seems that the difference is with getting quotes or not. How about
> changing org-as-get-selected-mail to make sure there is no quote? We
> could for instance test whether the first and last characters are
> quotes, and remove them if they are.

Would this work for you?

Alan


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org-mac-link.el-Fix-malformed-message-links.patch --]
[-- Type: text/x-patch, Size: 3199 bytes --]

From c6c1a05894e6fb1698d1a12bb2dc6a47874169f6 Mon Sep 17 00:00:00 2001
From: Alan Schmitt <alan.schmitt@polytechnique.org>
Date: Thu, 9 Oct 2014 14:12:05 +0200
Subject: [PATCH] org-mac-link.el: Fix malformed message links

* contrib/lisp/org-mac-link.el (org-mac-message-get-links): Fix and use the `org-mac-paste-applescript-links' helper.

The existing code inserted links which should have been "[[message:ABC][the subject]]"
as "[[essage:ABC][the subjec]]".

Based on a patch by Steve Purcell <steve@sanityinc.com>.
---
 contrib/lisp/org-mac-link.el | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/contrib/lisp/org-mac-link.el b/contrib/lisp/org-mac-link.el
index 979fb18..e1ab56d 100644
--- a/contrib/lisp/org-mac-link.el
+++ b/contrib/lisp/org-mac-link.el
@@ -234,11 +234,15 @@ When done, go grab the link, and insert it at point."
 (defun org-mac-paste-applescript-links (as-link-list)
   "Paste in a list of links from an applescript handler.
 The links are of the form <link>::split::<name>."
-  (let* ((link-list
+  (let* ((noquote-as-link-list 
+	  (if (string-prefix-p "\"" as-link-list) 
+	      (substring as-link-list 1 -1) 
+	    as-link-list))
+	 (link-list
           (mapcar (lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x)
 				  (setq x (match-string 1 x)))
 		    x)
-		  (split-string as-link-list "[\r\n]+")))
+		  (split-string noquote-as-link-list "[\r\n]+")))
          split-link URL description orglink orglink-insert rtn orglink-list)
     (while link-list
       (setq split-link (split-string (pop link-list) "::split::"))
@@ -828,27 +832,11 @@ The Org-syntax text will be pushed to the kill ring, and also returned."
   (interactive "sLink to (s)elected or (f)lagged messages: ")
   (setq select-or-flag (or select-or-flag "s"))
   (message "AppleScript: searching mailboxes...")
-  (let* ((as-link-list
-          (if (string= select-or-flag "s")
-              (org-as-get-selected-mail)
-	    (if (string= select-or-flag "f")
-		(org-as-get-flagged-mail)
-	      (error "Please select \"s\" or \"f\""))))
-         (link-list
-          (mapcar
-           (lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x) (setq x (match-string 1 x))) x)
-           (split-string (substring as-link-list 1 -1) "[\r\n]+")))
-         split-link URL description orglink orglink-insert rtn orglink-list)
-    (while link-list
-      (setq split-link (split-string (pop link-list) "::split::"))
-      (setq URL (car split-link))
-      (setq description (cadr split-link))
-      (when (not (string= URL ""))
-        (setq orglink (org-make-link-string URL description))
-        (push orglink orglink-list)))
-    (setq rtn (mapconcat 'identity orglink-list "\n"))
-    (kill-new rtn)
-    rtn))
+  (org-mac-paste-applescript-links
+   (cond
+    ((string= select-or-flag "s") (org-as-get-selected-mail))
+    ((string= select-or-flag "f") (org-as-get-flagged-mail))
+    (t (error "Please select \"s\" or \"f\"")))))
 
 (defun org-mac-message-insert-selected ()
   "Insert a link to the messages currently selected in Mail.app.
-- 
2.1.2


[-- Attachment #1.3: Type: text/plain, Size: 44 bytes --]



-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-10-09 12:15           ` Alan Schmitt
@ 2014-10-09 12:25             ` Steve Purcell
  2014-10-09 13:18               ` Alan Schmitt
  0 siblings, 1 reply; 9+ messages in thread
From: Steve Purcell @ 2014-10-09 12:25 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 556 bytes --]

On 9 Oct 2014, at 13:15, Alan Schmitt <alan.schmitt@polytechnique.org> wrote:

> On 2014-09-25 08:14, Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> 
>> On 2014-09-24 20:56, Steve Purcell <steve@sanityinc.com> writes:
>> 
>> It seems that the difference is with getting quotes or not. How about
>> changing org-as-get-selected-mail to make sure there is no quote? We
>> could for instance test whether the first and last characters are
>> quotes, and remove them if they are.
> 
> Would this work for you?


Yes, that works nicely here!

-Steve



[-- Attachment #2: Type: text/html, Size: 1539 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: PATCH: Fix malformed "message" links produced by org-mac-link.el
  2014-10-09 12:25             ` Steve Purcell
@ 2014-10-09 13:18               ` Alan Schmitt
  0 siblings, 0 replies; 9+ messages in thread
From: Alan Schmitt @ 2014-10-09 13:18 UTC (permalink / raw)
  To: Steve Purcell; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

On 2014-10-09 13:25, Steve Purcell <steve@sanityinc.com> writes:

>     Would this work for you?
>     
>
> Yes, that works nicely here!

Great, I pushed it.

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 494 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-10-09 13:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-24 10:39 PATCH: Fix malformed "message" links produced by org-mac-link.el Steve Purcell
2014-09-24 15:35 ` Alan Schmitt
2014-09-24 15:42   ` Steve Purcell
2014-09-24 19:01     ` Alan Schmitt
2014-09-24 19:56       ` Steve Purcell
2014-09-25  6:14         ` Alan Schmitt
2014-10-09 12:15           ` Alan Schmitt
2014-10-09 12:25             ` Steve Purcell
2014-10-09 13:18               ` Alan Schmitt

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).