[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC and articles generated by Shimbun
>> On Fri, 06 Jun 2003 15:56:36 +0900
>> 「土」== tsuchiya@pine.kuee.kyoto-u.ac.jp (TSUCHIYA Masatoshi) said as follows:
土> [emacs-w3m:00999] Constraint of shimbun header values の解決につい
土> ても考えると,きちんと shimbun-header-set-{subject,from} で対策を
土> 入れるべきでしょうねえ….
shimbun-header-{subject,from} で MIME encode を行い,
shimbun-header-set-{subject,from} で TAB や改行など不適当な文字を取り
除く,という対策を検討しています.検討中の変更を末尾に添付しました.
非常に影響範囲の広い変更なので,commit をためらっています.もう少し頭
を冷やして考え直してみますが,良かったら,添付のパッチを試して頂けると
ありがたいです.
--
土屋 雅稔 ( TSUCHIYA Masatoshi )
--- shimbun.el 7 Jun 2003 04:31:46 -0000 1.64
+++ shimbun.el 13 Jun 2003 14:49:39 -0000
@@ -139,67 +139,113 @@
(defalias 'shimbun-expand-url 'w3m-expand-url)
;;; Implementation of Header API.
-(defun shimbun-make-header (&optional number subject from date id
- references chars lines xref
- extra)
- (vector number subject from date id references chars lines xref extra))
-
-;;(defun shimbun-header-number (header)
-;; (aref header 0))
-
-(defun shimbun-header-subject (header)
- (aref header 1))
-
-(defun shimbun-header-set-subject (header subject)
- (aset header 1 subject))
-
-(defun shimbun-header-from (header)
- (aref header 2))
-
-(defun shimbun-header-set-from (header from)
- (aset header 2 from))
+(eval-and-compile
+ (luna-define-class shimbun-header ()
+ (number subject from date id references
+ chars lines xref extra))
+ (luna-define-internal-accessors 'shimbun-header))
+
+;; (defun shimbun-header-number (header)
+;; (shimbun-header-number-internal header))
+
+(defun shimbun-header-subject (header &optional no-encode)
+ (if no-encode
+ (shimbun-header-subject-internal header)
+ (shimbun-mime-encode-string
+ (shimbun-header-subject-internal header))))
+
+(defsubst shimbun-header-normalize (string)
+ (when string
+ (save-match-data
+ ;; To keep backward compatibility, decode a given string if
+ ;; required.
+ (if (string-match eword-encoded-word-regexp string)
+ (eword-decode-string string)
+ (with-temp-buffer
+ (insert string)
+ (shimbun-remove-markup)
+ (shimbun-decode-entities)
+ (subst-char-in-region ?\t ?\ (point-min) (point-max) t)
+ (subst-char-in-region ?\r ?\ (point-min) (point-max) t)
+ (subst-char-in-region ?\f ?\ (point-min) (point-max) t)
+ (subst-char-in-region ?\n ?\ (point-min) (point-max) t)
+ (buffer-string))))))
+
+(defun shimbun-header-set-subject (header subject &optional asis)
+ (shimbun-header-set-subject-internal header
+ (if asis
+ subject
+ (shimbun-header-normalize subject))))
+
+(defun shimbun-header-from (header &optional no-encode)
+ (if no-encode
+ (shimbun-header-from-internal header)
+ (shimbun-mime-encode-string
+ (shimbun-header-from-internal header))))
+
+(defun shimbun-header-set-from (header from &optional asis)
+ (shimbun-header-set-from-internal header
+ (if asis
+ from
+ (shimbun-header-normalize from))))
(defun shimbun-header-date (header)
- (aref header 3))
+ (shimbun-header-date-internal header))
(defun shimbun-header-set-date (header date)
- (aset header 3 date))
+ (shimbun-header-set-date-internal header date))
(defun shimbun-header-id (header)
- (aref header 4))
+ (shimbun-header-id-internal header))
(defun shimbun-header-set-id (header id)
- (aset header 4 id))
+ (shimbun-header-set-id-internal header id))
(defun shimbun-header-references (header)
- (aref header 5))
+ (shimbun-header-references-internal header))
(defun shimbun-header-set-references (header references)
- (aset header 5 references))
+ (shimbun-header-set-references-internal header references))
(defun shimbun-header-chars (header)
- (aref header 6))
+ (shimbun-header-chars-internal header))
(defun shimbun-header-set-chars (header chars)
- (aset header 6 chars))
+ (shimbun-header-set-chars-internal header chars))
(defun shimbun-header-lines (header)
- (aref header 7))
+ (shimbun-header-lines-internal header))
(defun shimbun-header-set-lines (header lines)
- (aset header 7 lines))
+ (shimbun-header-set-lines-internal header lines))
(defun shimbun-header-xref (header)
- (aref header 8))
+ (shimbun-header-xref-internal header))
(defun shimbun-header-set-xref (header xref)
- (aset header 8 xref))
+ (shimbun-header-set-xref-internal header xref))
(defun shimbun-header-extra (header)
- (aref header 9))
+ (shimbun-header-extra-internal header))
(defun shimbun-header-set-extra (header extra)
- (aset header 9 extra))
+ (shimbun-header-set-extra-internal header extra))
+
+(defun shimbun-make-header (&optional number subject from date id
+ references chars lines xref
+ extra asis)
+ (let ((new (luna-make-entity 'shimbun-header :number number)))
+ (inline
+ (shimbun-header-set-subject new subject asis)
+ (shimbun-header-set-from new from asis)
+ (shimbun-header-set-date new date)
+ (shimbun-header-set-id new id)
+ (shimbun-header-set-references new references)
+ (shimbun-header-set-chars new chars)
+ (shimbun-header-set-lines new lines)
+ (shimbun-header-set-xref new xref)
+ (shimbun-header-set-extra new extra))
+ new))
;; Inline functions for the internal use.
(defsubst shimbun-article-url (shimbun header)
@@ -332,8 +378,9 @@
(refs (shimbun-header-references header))
(reply-to (shimbun-reply-to shimbun))
x-face)
- (insert "Subject: " (or (shimbun-header-subject header) "(none)") "\n"
- "From: " (or from "(nobody)") "\n"
+ (insert "Subject: "
+ (or (shimbun-header-subject-internal header) "(none)") "\n"
+ "From: " (or (shimbun-header-from-internal header) "(nobody)") "\n"
"Date: " (or (shimbun-header-date header) "") "\n"
"Message-ID: " (shimbun-header-id header) "\n")
(when reply-to
@@ -365,7 +412,8 @@
(shimbun-x-face shimbun)))
(insert x-face)
(unless (bolp)
- (insert "\n")))))
+ (insert "\n"))
+ (mime-encode-header-in-buffer))))
;;; Implementation of Shimbun API.
@@ -489,8 +537,8 @@
(luna-define-method shimbun-from-address ((shimbun shimbun))
(format "%s (%s) <%s>"
- (shimbun-mime-encode-string (shimbun-server-name shimbun))
- (shimbun-mime-encode-string (shimbun-current-group-name shimbun))
+ (shimbun-server-name shimbun)
+ (shimbun-current-group-name shimbun)
(or (shimbun-from-address-internal shimbun)
(shimbun-reply-to shimbun))))
@@ -585,6 +633,7 @@
is enclosed by at least one regexp grouping construct."
(let ((open-paren (if paren "\\(" "")) (close-paren (if paren "\\)" "")))
(concat open-paren (mapconcat 'regexp-quote strings "\\|") close-paren))))
+
(defun shimbun-decode-entities-string (string)
"Decode entities in the STRING."
(with-temp-buffer