emacs-pretest-bug
[Top][All Lists]
Advanced

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

browse-url rfc2368 support


From: Dave Love
Subject: browse-url rfc2368 support
Date: Wed, 03 Mar 2004 23:23:38 +0000
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.2 (gnu/linux)

The change to rfc2368.el itself is just a simplification using the
functionality it said was missing -- it isn't necessary.

2004-01-12  Dave Love  <address@hidden>

        * net/browse-url.el (rfc2368-parse-mailto-url): Autoload.
        (browse-url-mail): Use it.

        * mail/rfc2368.el (rfc2368-unhexify-char): Deleted.
        (rfc2368-unhexify-string): Use replace-regexp-in-string.

--- net/browse-url.el.~1.32.~   Wed Sep  3 15:59:33 2003
+++ net/browse-url.el   Mon Jan 12 18:31:49 2004
@@ -1301,9 +1301,11 @@
 
 ;; --- mailto ---
 
+(autoload 'rfc2368-parse-mailto-url "rfc2368")
+
 ;;;###autoload
 (defun browse-url-mail (url &optional new-window)
-  "Open a new mail message buffer within Emacs.
+  "Open a new mail message buffer within Emacs for the RFC 2368 URL.
 Default to using the mailto: URL around or before point as the
 recipient's address.  Supplying a non-nil interactive prefix argument
 will cause the mail to be composed in another window rather than the
@@ -1318,14 +1320,24 @@
 used instead of `browse-url-new-window-flag'."
   (interactive (browse-url-interactive-arg "Mailto URL: "))
   (save-excursion
-    (let ((to (if (string-match "^mailto:"; url)
-                 (substring url 7)
-               url)))
+    (let* ((alist (rfc2368-parse-mailto-url url))
+          (to (assoc "To" alist))
+          (subject (assoc "Subject" alist))
+          (body (assoc "Body" alist))
+          (rest (delete to (delete subject (delete 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 nil nil nil
-                                    (list 'insert-buffer (current-buffer)))
-       (compose-mail to nil nil nil nil
-                     (list 'insert-buffer (current-buffer)))))))
+         (compose-mail-other-window to subject rest nil
+                                    (if body
+                                        (list 'insert body)
+                                      (list 'insert-buffer (current-buffer))))
+       (compose-mail to subject rest nil nil
+                     (if body
+                         (list 'insert body)
+                       (list 'insert-buffer (current-buffer))))))))
 
 ;; --- Random browser ---
 
--- mail/rfc2368.el.~1.5.~      Wed Sep  3 15:59:27 2003
+++ mail/rfc2368.el     Mon Jan 12 18:07:58 2004
@@ -76,39 +76,13 @@
 (defconst rfc2368-mailto-query-index 4
   "Describes the portion of the url after '?'.")
 
-;; for dealing w/ unhexifying strings, my preferred approach is to use
-;; a 'string-replace-match-using-function' which can perform a
-;; string-replace-match and compute the replacement text based on a
-;; passed function -- however, emacs doesn't seem to have such a
-;; function yet :-(
-
-;; for the moment a rip-off of url-unhex (w3/url.el)
-(defun rfc2368-unhexify-char (char)
-  "Unhexify CHAR -- e.g. %20 -> <SPC>."
-  (if (> char ?9)
-      (if (>= char ?a)
-         (+ 10 (- char ?a))
-       (+ 10 (- char ?A)))
-    (- char ?0)))
-
-;; for the moment a rip-off of url-unhex-string (w3/url.el) (slightly modified)
 (defun rfc2368-unhexify-string (string)
   "Unhexify STRING -- e.g. 'hello%20there' -> 'hello there'."
-  (let ((case-fold-search t)
-       (result ""))
-    (while (string-match "%[0-9a-f][0-9a-f]" string)
-      (let* ((start (match-beginning 0))
-            (hex-code (+ (* 16
-                            (rfc2368-unhexify-char (elt string (+ start 1))))
-                         (rfc2368-unhexify-char (elt string (+ start 2))))))
-       (setq result (concat
-                     result (substring string 0 start)
-                     (char-to-string hex-code))
-             string (substring string (match-end 0)))))
-    ;; it seems clearer to do things this way than to just return:
-    ;; (concat result string)
-    (setq result (concat result string))
-    result))
+  (replace-regexp-in-string "%[[:xdigit:]]\\{2\\}"
+                           (lambda (match)
+                             (string (string-to-number (substring match 1)
+                                                       16)))
+                           string t t))
 
 (defun rfc2368-parse-mailto-url (mailto-url)
   "Parse MAILTO-URL, and return an alist of header-name, header-value pairs.




reply via email to

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