* ptexinfmt.el: Support @indicateurl, @LaTeX.
[elisp/wanderlust.git] / utils / wl-mailto.el
1 ;;; wl-mailto.el -- some mailto support for wanderlust
2
3 ;;; Copyright (C) 1999 Sen Nagata
4
5 ;; Author: Sen Nagata <sen@eccosys.com>
6 ;; Version: 0.5
7 ;; License: GPL 2
8 ;; Warning: not optimized at all
9
10 ;; This file is not a part of GNU Emacs.
11
12 ;;; Commentary:
13 ;;
14 ;; required elisp packages:
15 ;;
16 ;;   -wl (>= 0.9.6?)
17 ;;
18 ;;   -rfc2368.el
19 ;;   -thingatpt.el or browse-url.el
20 ;;
21 ;; installation:
22 ;;
23 ;;   -put this file (and rfc2368.el) in an appropriate directory (so Emacs
24 ;;    can find it)
25 ;;
26 ;;   <necessary>
27 ;;   -put:
28 ;;
29 ;;     (add-hook 'wl-init-hook (lambda () (require 'wl-mailto)))
30 ;;
31 ;;    in .emacs or .wl
32 ;;
33 ;; details:
34 ;;
35 ;;   this package provides a number of interactive functions
36 ;; (commands) for the user.  each of the commands ultimately creates a
37 ;; draft message based on some information.  the names of the commands
38 ;; and brief descriptions are:
39 ;;
40 ;;     1) wl-mailto-compose-message-from-mailto-url
41 ;;            make a draft message from a user-specified mailto: url
42 ;;
43 ;;     2) wl-mailto-compose-message-from-mailto-url-at-point
44 ;;            make a draft message from a mailto: url at point
45 ;;
46 ;; usage:
47 ;;
48 ;;   -invoke wl
49 ;;   -try out the commands mentioned above in 'details'
50
51 ;;; History:
52 ;;
53 ;; 0.5
54 ;;
55 ;;   wl-user-agent functionality merged into wl-draft.el, so removed
56 ;;    dependency
57 ;;
58 ;; 1999-06-24:
59 ;;
60 ;;   incorporated a patch from Kenichi OKADA for
61 ;;     wl-mailto-compose-message-from-mailto-url-at-point
62 ;;
63 ;; 1999-06-11:
64 ;;
65 ;;   fixed a typo
66 ;;
67 ;; 0.4
68 ;;
69 ;; 1999-06-01:
70 ;;
71 ;;   checkdoc checking
72 ;;   xemacs compatibility
73 ;;
74 ;; 1999-05-31:
75 ;;
76 ;;   rewrote to use rfc2368.el and wl-user-agent.el
77
78 ;;; Code:
79 (defconst wl-mailto-version "wl-mailto.el 0.5")
80
81 ;; how should we handle the dependecy on wl?
82 ;; will this work?
83 (eval-when-compile
84   (require 'wl)
85   (defun wl-mailto-url-at-point ()))
86
87
88 ;; use rfc2368 support -- should be usable for things other than wl too
89 (require 'rfc2368)
90
91 ;; yucky compatibility stuff -- someone help me w/ this, please...
92 (if (and (string-match "^XEmacs \\([0-9.]+\\)" (emacs-version))
93          (< (string-to-int (match-string 1 (emacs-version))) 21))
94     ;; for xemacs versions less than 21, use browse-url.el
95     (progn
96       (require 'browse-url)
97       (fset 'wl-mailto-url-at-point
98             'browse-url-url-at-point))
99   ;; for everything else, use thingatpt.el
100   (progn
101     (require 'thingatpt)
102     (fset 'wl-mailto-url-at-point
103           (lambda ()
104             (thing-at-point 'url)))))
105
106 (defun wl-mailto-compose-message-from-mailto-url (url &optional dummy)
107   "Compose a message from URL (RFC 2368).
108 The optional second argument, DUMMY, exists to match the interface
109 provided by `browse-url-mail' (w3) -- DUMMY does not do anything."
110   (interactive "sURL: ")
111   (if (string-match rfc2368-mailto-regexp url)
112       (let* ((other-headers (rfc2368-parse-mailto-url url))
113              (to (cdr (assoc-ignore-case "to" other-headers)))
114              (subject (cdr (assoc-ignore-case "subject" other-headers))))
115
116         (wl-user-agent-compose to subject other-headers))
117     (message "Not a mailto: url.")))
118
119 ;; prepare a message from a mailto: url at point
120 (defun wl-mailto-compose-message-from-mailto-url-at-point ()
121   "Draft a new message based on URL (RFC 2368) at point."
122   (interactive)
123   (let ((url (wl-mailto-url-at-point)))
124     (if (and url (string-match rfc2368-mailto-regexp url))
125         (wl-mailto-compose-message-from-mailto-url url)
126       ;; tell the user that we didn't find a mailto: url at point
127       (message "No mailto: url detected at point."))))
128
129 ;; since this will be used via 'require'...
130 (provide 'wl-mailto)
131
132 ;;; wl-mailto.el ends here