[Mew-dist 09897] Re: request for mew-user-agent-compose
sen_ml at example.com
sen_ml at example.com
1999年 7月 30日 (金) 14:09:43 JST
At around Fri, 30 Jul 1999 13:48:56 +0900,
Hideyuki SHIRAI (白井秀行) <shirai at example.com> may have mentioned:
> From: sen_ml at example.com <sen_ml at example.com> さん曰く
> Subject: [Mew-dist 09892] Re: request for mew-user-agent-compose
> Message-ID: <19990730132533V.1001 at example.com>
> Date: Fri, 30 Jul 1999 13:26:14 +0900
>
> sen> # いま mew-mailto.el を変更しているところです。できあがったら送ります。
>
> mew-browse.el は変更したので送ります。:-)
あとで試してみます (^^)
mew-mailto.el を変更しました。rfc2368.el というものに依存する様になりました。
添付します。mailto.el がもういらなくなるはずです (というか、rfc2368.el は
replacement だと思って下さい)。
# rfc2368.el は Emacs の一部になる予定です。いま FSF とそこらへんの
やりとりをしています。
sen_ml @何でこういう日に限って時間が少ないの (; ;)
-------------- next part --------------
;;; -*- emacs-lisp -*-
;;;
;;; name: mew-mailto.el
;;; version: 0.6
;;; description: some mailto support for mew
;;; creation date: 1998-11-07
;;; author: "Sen Nagata" <sen at example.com>
;;; warning: not optimized at all
;;; required:
;;;
;;; -mew (1.94 and up -- uses mew-user-agent-compose)
;;; -rfc2368.el
;;; -thingatpt.el (comes w/ emacs) for thing-at-pt
;;; installation:
;;;
;;; -put this file (and rfc2368.el) in an appropriate directory (so emacs
;;; can find it)
;;;
;;; <necessary>
;;; -put:
;;;
;;; (add-hook 'mew-init-hook (lambda () (require 'mew-mailto)))
;;;
;;; in your .emacs file.
;;; details:
;;;
;;; this package provides a number of interactive functions
;;; (commands) for the user. each of the commands ultimately creates a
;;; draft message based on some information. the names of the commands
;;; and brief descriptions are:
;;;
;;; 1) mew-mailto-compose-message-from-mailto-url
;;; make a draft message from a user-specified mailto: url
;;;
;;; 2) mew-mailto-compose-message-from-mailto-url-at-point
;;; make a draft message from a mailto: url at point
;;; usage:
;;;
;;; -invoke mew
;;; -try out the commands mentioned above in 'details'
;;; History:
;;
;; 0.6
;;
;; 1999-07-30
;;
;; fixed a bug in mew-mailto-compose-message-from-mailto-url that could
;; lead to duplicate headers in messages
;;
;; 1999-06-01
;;
;; added compatibility garbage for xemacs -- thingatpt.el vs browse-url.el
;;
;; 1999-05-31
;;
;; rewrote to use rfc2368.el
;; removed a lot of functionality
;;
;; 0.5
;;
;; 1999-05-04:
;;
;; modified the interface to mew-mailto-compose-message-from-mailto-url
;; as suggested by Umekichi <umekichi at example.com>. see the interface
;; to browse-url-mail in browse-url.el for details.
;; how should we handle the dependecy on mew?
;; doing the following seems to have catastrophic effects on my machine :-(
;(require 'mew)
;; will this work?
(eval-when-compile
(require 'mew))
(defconst mew-mailto-version "mew-mailto.el 0.6")
;; use rfc2368 support -- should be useable for things other than mew too
(require 'rfc2368)
;; yucky compatibility stuff...
(if (and (string-match "^XEmacs \\([0-9.]+\\)" (emacs-version))
(< (string-to-int (match-string 1 (emacs-version))) 21))
;; for xemacs versions less than 21, use browse-url.el
(progn
(require 'browse-url)
(fset 'mew-mailto-url-at-point
'browse-url-url-at-point))
;; for everything else, use thingatpt.el
(progn
(require 'thingatpt)
(fset 'mew-mailto-url-at-point
(lambda ()
(thing-at-point 'url)))))
(defun mew-mailto-compose-message-from-mailto-url (url &optional dummy)
"Compose a messsage from URL. The optional second argument, DUMMY, exists
to match the interface provided by browse-url-mail -- DUMMY does not do
anything."
(interactive "sURL: ")
(if (string-match rfc2368-mailto-regexp url)
(let* ((other-headers (rfc2368-parse-mailto-url url))
;; the reason i'm bothering to extract To and Subject is
;; because i want them to appear at reasonable places in
;; the headers (not in some random order) -- i'll need to
;; do the same for any other headers that work that way too...
(to (cdr (assoc-ignore-case "to" other-headers)))
(subject (cdr (assoc-ignore-case "subject" other-headers))))
;; if these are not removed from other-headers, we will get duplicates
(remove-alist 'other-headers "To")
(remove-alist 'other-headers "Subject")
;; mew doesn't handle specifying a message body via
;; mew-user-agent-compose yet -- rms said he would support
;; specifying a body via the compose-mail interface after
;; emacs 20.4 is released
(mew-user-agent-compose to subject other-headers))
(message "Not a mailto: url.")))
;; prepare a message from a mailto: url at point
(defun mew-mailto-compose-message-from-mailto-url-at-point ()
"Compose a message from a mailto url found at point."
(interactive)
(let ((url (mew-mailto-url-at-point)))
(if (string-match rfc2368-mailto-regexp url)
(mew-mailto-compose-message-from-mailto-url url)
;; tell the user that we didn't find a mailto: url at point
(message "No mailto: url detected at point."))))
;; since this will be used via 'require'...
(provide 'mew-mailto)
;; end of mew-mailto.el
-------------- next part --------------
;;; rfc2368.el --- support for rfc 2368
;;; Copyright 1999 Sen Nagata <sen at example.com>
;; Keywords: rfc 2368, mailto, mail
;; Version: 0.3
;; License: GPL 2
;; This file is not a part of GNU Emacs.
;;; Commentary:
;;
;; notes:
;;
;; -repeat after me: "the colon is not part of the header name..."
;; -if w3 becomes part of emacs, then it may make sense to have this
;; file depend on w3 -- the maintainer of w3 says merging w/ emacs
;; is planned!
;;
;; historical note:
;;
;; this is intended as a replacement for mailto.el
;;
;; acknowledgements:
;;
;; the functions that deal w/ unhexifying in this file were basically
;; taken from w3 -- i hope to replace them w/ something else soon OR
;; perhaps if w3 becomes a part of emacs soon, use the functions from w3.
;;; History:
;;
;; 0.3:
;;
;; added the constant rfc2368-version
;; implemented first potential fix for a bug in rfc2368-mailto-regexp
;; implemented first potential fix for a bug in rfc2368-parse-mailto
;; (both bugs reported by Kenichi OKADA)
;;
;; 0.2:
;;
;; started to use checkdoc
;;
;; 0.1:
;;
;; initial implementation
;;; Code:
(defconst rfc2368-version "rfc2368.el 0.3")
;; only an approximation?
;; see rfc 1738
(defconst rfc2368-mailto-regexp
"^\\(mailto:\\)\\([^?]+\\)*\\(\\?\\(.*\\)\\)*"
"Regular expression to match and aid in parsing a mailto url.")
;; describes 'mailto:'
(defconst rfc2368-mailto-scheme-index 1
"Describes the 'mailto:' portion of the url.")
;; i'm going to call this part the 'prequery'
(defconst rfc2368-mailto-prequery-index 2
"Describes the portion of the url between 'mailto:' and '?'.")
;; i'm going to call this part the 'query'
(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))
(defun rfc2368-parse-mailto-url (mailto-url)
"Parse MAILTO-URL, and return an alist of header-name, header-value pairs.
MAILTO-URL should be a RFC 2368 (mailto) compliant url. A cons cell w/ a
key of 'Body' is a special case and is considered a header for this purpose.
The returned alist is intended for use w/ the `compose-mail' interface.
Note: make sure MAILTO-URL has been 'unhtmlized' (e.g. & -> &), before
calling this function."
(let ((case-fold-search t)
prequery query headers-alist)
(if (string-match rfc2368-mailto-regexp mailto-url)
(progn
(setq prequery
(match-string rfc2368-mailto-prequery-index mailto-url))
(setq query
(match-string rfc2368-mailto-query-index mailto-url))
;; build alist of header name-value pairs
(if (not (null query))
(setq headers-alist
(mapcar
(lambda (x)
(let* ((temp-list (split-string x "="))
(header-name (car temp-list))
(header-value (cadr temp-list)))
;; return ("Header-Name" . "header-value")
(cons
(capitalize (rfc2368-unhexify-string header-name))
(rfc2368-unhexify-string header-value))))
(split-string query "&"))))
;; deal w/ multiple 'To' recipients
(if prequery
(progn
(if (assoc "To" headers-alist)
(let* ((our-cons-cell
(assoc "To" headers-alist))
(our-cdr
(cdr our-cons-cell)))
(setcdr our-cons-cell (concat our-cdr ", " prequery)))
(setq headers-alist
(cons (cons "To" prequery) headers-alist)))))
headers-alist)
(error "Failed to match a mailto: url"))
))
(provide 'rfc2368)
;;; rfc2368.el ends here
Mew-dist メーリングリストの案内