info-gnus-english
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xdg-email vs browse-url-mail


From: Dmitry Alexandrov
Subject: Re: xdg-email vs browse-url-mail
Date: Fri, 15 Jul 2016 00:09:31 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Kevin Brubeck Unhammer <unhammer@fsfe.org> writes:

> I just tried using browse-url-mail as a mailto-handler with the below
> script as my mail handler (set in XFCE settings):
>
> #!/bin/bash
> mailto="${*//\"/}"

...

> if [[ ! ${mailto} =~ ^mailto: ]]; then
>     mailto="mailto:${mailto}";
> fi

Does not xdg-email(1) already do that?

> emacsclient -c --eval "(browse-url-mail \"${mailto}\")"
>
> It seems to work with xdg-email, but when I use --attach to attach a
> file, it just appears as an "Attach: /path/to/file" header instead of
> the usual &lt;#part thing. After sending, nothing is attached to the
> received message that I can tell. Is there a way to make browse-url-mail
> do the right thing, or to make message-mode treat that "Attach:" line
> correctly?

Try this:

diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index c0b3591..a4d47f6 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -1562,31 +1562,42 @@ When called non-interactively, optional second argument 
NEW-WINDOW is
 used instead of `browse-url-new-window-flag'."
   (interactive (browse-url-interactive-arg "Mailto URL: "))
   (save-excursion
-    (let* ((alist (rfc2368-parse-mailto-url url))
-          (to (assoc "To" alist))
-          (subject (assoc "Subject" alist))
-          (body (assoc "Body" alist))
-          (rest (delq to (delq subject (delq body alist))))
-          (to (cdr to))
-          (subject (cdr subject))
-          (body (cdr body))
-          (mail-citation-hook (unless body mail-citation-hook)))
-      (if (browse-url-maybe-new-window new-window)
-         (compose-mail-other-window to subject rest nil
-                                    (list 'insert-buffer (current-buffer)))
-       (compose-mail to subject rest nil nil
-                     (list 'insert-buffer (current-buffer))))
-      (when body
-       (goto-char (point-min))
-       (unless (or (search-forward (concat "\n" mail-header-separator "\n")
-                                   nil 'move)
-                   (bolp))
-         (insert "\n"))
-       (goto-char (prog1
-                      (point)
-                    (insert (replace-regexp-in-string "\r\n" "\n" body))
-                    (unless (bolp)
-                      (insert "\n"))))))))
+    (let ((headers (rfc2368-parse-mailto-url url))
+          to subject body attaches rest)
+      (dolist (header headers)
+        (cond
+         ((equal (car header) "To")
+          (setq to (cdr header)))
+         ((equal (car header) "Subject")
+          (setq subject (cdr header)))
+         ((equal (car header) "Body")
+          (setq body (cdr header)))
+         ((equal (car header) "Attach")
+          (add-to-list 'attaches (cdr header)))
+         (t
+          (push header rest))))
+      (let ((mail-citation-hook (unless body mail-citation-hook)))
+        (if (browse-url-maybe-new-window new-window)
+            (compose-mail-other-window to subject rest nil
+                                       (list 'insert-buffer (current-buffer)))
+          (compose-mail to subject rest nil nil
+                        (list 'insert-buffer (current-buffer))))
+        (when body
+          (goto-char (point-min))
+          (unless (or (search-forward (concat "\n" mail-header-separator "\n")
+                                      nil 'move)
+                      (bolp))
+            (insert "\n"))
+          (goto-char (prog1
+                         (point)
+                       (insert (replace-regexp-in-string "\r\n" "\n" body))
+                       (unless (bolp)
+                         (insert "\n")))))
+        (when attaches
+          (if (not mml-mode)
+              (error "Enable MML mode if you want to attach files")
+            (dolist (attach attaches)
+              (mml-attach-file attach nil nil "attachment"))))))))
 
 ;; --- Random browser ---
 
(Note, that I have virtually no experience with elisp, so use at your
own risk. :-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]