[Mew-dist 2011] IMAP patch for 1.91- (dirty)

若宮賢二 wkenji at example.com
1997年 9月 14日 (日) 18:44:45 JST


若宮@富士通研です。

以前に少し話が出ましたが、Mew-1.91- (IM-65 以降) で取り敢えず IMAP フォ
ルダを覗けるようにパッチを作ってみました。Mew へのパッチのみです。
#ホントに取り敢えずだし遅いので、恐らく実用には耐えません。

ローカルフォルダ同様、.mew-cache に imls の結果をキャッシュします。保
存先のディレクトリは mew-imap-path/SERVER/FOLDER/ としています 
(mew-expand-folder に手を入れました)。mew-imap-path は新規に入れたユー
ザオプション変数で、デフォルト値は "~/Mail/IMAP" です。キャッシュ用の
ディレクトリは予め手動で作っておく必要があります。

また、上の SERVER を Mew に伝えるために、.im/Config の InboxFolder や 
C-u M-x mew や g (mew-summary-goto-folder) で IMAP フォルダを指定する
際は、必ず "%inbox at example.com" のようにサーバ名を指定する必要があります。
#impath で?デフォルトの各サーバ名やユーザ名が得られると便利かも知れ
#ないです。

それと、ちょうど今日 motonori さんが impwagent をポストされたところで
言いにくいのですが、パスワード保持を ange-ftp の方式&関数で行なってい
ます…(私も怒られる)。入力されたサーバ名はここでのハッシュキーとしても
利用しています。

imcat はパスワード渡しのために start-process で起動して、終了するまで
待機するようにしています。

n、n、n、と試してみて下さい;-)。C-n すればいいんですけど。

// Kenji    | mailto:wkenji at example.com (office)
// Wakamiya | mailto:wkenji at example.com (private)
-------------- next part --------------
diff -aruN mew-1.91-/mew-decode.el mew-1.91+/mew-decode.el
--- mew-1.91-/mew-decode.el	Tue Aug 26 09:55:16 1997
+++ mew-1.91+/mew-decode.el	Sun Sep 14 15:53:53 1997
@@ -285,9 +285,21 @@
   (if (and mew-temacs-p mew-mule-p) (setq mc-flag nil))
   (mew-erase-buffer)
   (cond
-   ((mew-folder-newsp fld)
-    (mew-piolet mew-cs-noconv-eol mew-cs-noconv
-      (call-process mew-prog-imcat nil t nil (format "--src=%s" fld) msg)))
+   ((or (mew-folder-newsp fld)
+	(mew-folder-imapp fld))
+    (let (dispproc)
+      (setq dispproc (start-process mew-prog-imcat
+				    (current-buffer)
+				    mew-prog-imcat
+				    (format "--src=%s" fld) msg))
+      (mew-set-process-cs dispproc mew-cs-noconv-eol mew-cs-noconv)
+      (set-process-filter dispproc 'mew-summary-display-filter)
+      (set-process-sentinel dispproc 'mew-summary-display-sentinel)
+      (process-kill-without-query dispproc)
+      (setq mew-summary-dispbuf-string "")
+      (setq mew-summary-displaying-folder fld)
+      (while (eq (process-status dispproc) 'run)
+	(accept-process-output dispproc))))
    (t
     (let ((file (mew-expand-folder fld msg)))
       (mew-frwlet mew-cs-noconv-eol mew-cs-noconv
diff -aruN mew-1.91-/mew-func.el mew-1.91+/mew-func.el
--- mew-1.91-/mew-func.el	Fri Aug 29 20:49:58 1997
+++ mew-1.91+/mew-func.el	Sun Sep 14 15:54:00 1997
@@ -282,6 +282,10 @@
   (string-match "^=" folder)
   )
 
+(defun mew-folder-imapp (folder)
+  (string-match "^%" folder)
+  )
+
 (defun mew-folder-to-dir (folder)
   (if (string-match "^[+=]" folder)
       (substring folder 1 nil)
@@ -297,7 +301,15 @@
       (setq dir (expand-file-name subdir mew-mail-path)))
      ((char-equal prefix-char ?=)
       (setq dir (expand-file-name subdir mew-news-path)))
-     )
+     ((char-equal prefix-char ?%)
+      (let (fldr host)
+	(string-match
+	 "^\\([^:]+\\)\\(:[^/@]+\\)?\\(/[^@]+\\)?@\\(.+\\)$" subdir)
+	(setq fldr (substring subdir (match-beginning 1) (match-end 1)))
+	(setq host (substring subdir (match-beginning 4) (match-end 4)))
+	(setq dir (expand-file-name
+		   (concat host mew-path-separator fldr) mew-imap-path)))
+      ))
     (if message
 	(expand-file-name message dir)
       dir)
diff -aruN mew-1.91-/mew-scan.el mew-1.91+/mew-scan.el
--- mew-1.91-/mew-scan.el	Tue Aug 26 09:58:09 1997
+++ mew-1.91+/mew-scan.el	Sun Sep 14 15:54:06 1997
@@ -51,8 +51,8 @@
     (if (or (interactive-p)
 	    (mew-folder-newsp folder)
 	    (and mew-summary-cache-use
-		 (not (mew-folder-newsp folder))
-		 (mew-summary-folder-dir-newp)))
+		 (or (mew-folder-imapp folder)
+		     (mew-summary-folder-dir-newp))))
 	(let ((range (mew-input-range folder)))
 	  (or arg (goto-char (point-max)))
 	  (mew-summary-scan-body mew-prog-imls 
@@ -143,13 +143,24 @@
 	  (concat mew-summary-buffer-string string)) ;; nil can concat
     (cond
      ;; just for imls
-     ((string-match mew-prog-imget (process-name process))
+     ((or (string-match mew-prog-imget (process-name process))
+	  (string-match mew-prog-imls  (process-name process)))
       (if (string-match "^Password" mew-summary-buffer-string)
-	  (progn
+	  (let ((folder (buffer-name)))
 	    (setq mew-summary-buffer-string "")
-	    (process-send-string
-	     process
-	     (format "%s\n" (mew-read-passwd "Enter password : ")))
+	    (if (mew-folder-imapp folder)
+		(let (host pass)
+		  (string-match
+		   "^\\(%[^:]+\\)\\(:[^/@]+\\)?\\(/[^@]+\\)?@\\(.+\\)$" folder)
+		  (setq host (substring folder
+					(match-beginning 4) (match-end 4)))
+		  (setq pass (ange-ftp-get-hash-entry host
+						      mew-passwd-hashtable))
+		  (process-send-string process (format "%s\n" pass)))
+	      (process-send-string
+	       process
+	       (format "%s\n" (mew-read-passwd "Enter password : ")))
+	      )
 	    ))
       ;; Skip greeting...
       (if (string-match "^imget: Getting new messages.*\n"
@@ -198,7 +209,10 @@
 	    (setq msg (concat (mew-match 1 mew-summary-buffer-string) 
 			      " message(s)")))
 	   (t
-	    (setq msg (format "Getting %s ... done" folder)))
+	    (if (mew-folder-imapp folder)
+		(setq msg (format "Getting %%%s ... done" folder))
+	      (setq msg (format "Getting %s ... done" folder)))
+	    )
 	   ))
 	 ((string-match mew-prog-imls prog)
 	  (cond
@@ -208,7 +222,11 @@
 	   ((string-match (format "^%s: ERROR: \\([^\n]*\\)" prog)
 			  mew-summary-buffer-string)
 	    (message "List error: %s" (mew-match 1 mew-summary-buffer-string)))
-	   (t (setq msg (format "Listing %s ... done" folder)))
+	   (t
+	    (if (mew-folder-imapp folder)
+		(setq msg (format "Listing %%%s ... done" folder))
+	      (setq msg (format "Listing %s ... done" folder)))
+	    )
 	   ))
 	 )
 	(if msg
diff -aruN mew-1.91-/mew-summary.el mew-1.91+/mew-summary.el
--- mew-1.91-/mew-summary.el	Thu Aug 28 06:53:45 1997
+++ mew-1.91+/mew-summary.el	Sun Sep 14 15:54:14 1997
@@ -462,15 +462,31 @@
 (defun mew-summary-goto-folder ()
   (interactive)
   (let* ((folder (mew-input-folder mew-inbox-folder))
-	 (dir (mew-expand-folder folder))
+	 (dir (or (mew-expand-folder folder) ""))
 	 new-folder)
-    (if (not (or (mew-folder-newsp folder) (file-directory-p dir)))
+    (if (not (or (mew-folder-newsp folder)
+		 (mew-folder-imapp folder)
+		 (file-directory-p dir)))
         (message "No such folder %s" folder)
       (if (get-buffer folder)
 	  (switch-to-buffer folder)
+	(if (mew-folder-imapp folder)
+	    (let (host)
+	      (require 'ange-ftp)
+	      (defvar mew-passwd-hashtable (ange-ftp-make-hashtable))
+	      (string-match
+	       "^\\(%[^:]+\\)\\(:[^/@]+\\)?\\(/[^@]+\\)?@\\(.+\\)$" folder)
+	      (setq host (substring folder (match-beginning 4) (match-end 4)))
+	      (if (not (ange-ftp-get-hash-entry host mew-passwd-hashtable))
+		  (let (pass)
+		    (setq pass (mew-read-passwd "Enter password : "))
+		    (ange-ftp-put-hash-entry host pass mew-passwd-hashtable)))
+	      ))
 	(mew-summary-folder-create folder)
 	(setq new-folder t))
-      (if (and mew-summary-trace-directory (not (mew-folder-newsp folder)))
+      (if (and mew-summary-trace-directory
+	       (not (mew-folder-newsp folder))
+	       (not (mew-folder-imapp folder)))
 	  (cd dir))
       (mew-summary-ls t new-folder)
       )))
@@ -632,7 +648,8 @@
     (if (not (or (file-exists-p (mew-expand-folder 
 				 (if fld fld (car ofld-msg))
 				 (if msg msg (cdr ofld-msg))))
-		 (mew-folder-newsp fld)))
+		 (mew-folder-newsp fld)
+		 (mew-folder-imapp fld)))
 	(message "File does not exist.")
       (mew-summary-toggle-disp-msg 'on)
       (unwind-protect
@@ -765,6 +782,9 @@
 	    (setq mew-summary-buffer-left-msgs (int-to-string (1- left))))))
     ))
 
+(defvar mew-summary-dispbuf-string nil)
+(defvar mew-summary-displaying-folder nil)
+
 (defun mew-summary-display-message (fld msg buf &optional analysis nodisplay)
   ;; message buffer
   (let ((hit nil) (zmacs-regions nil) (buffer-read-only nil)
@@ -785,11 +805,27 @@
      ((and (not analysis)
 	   (not (mew-folder-newsp fld)) ;; xxx
 	   (or (not mew-analysis)
-	       (and (> (mew-file-size file) mew-file-max-size)
+	       (and (not (mew-folder-imapp fld))
+		    (> (mew-file-size file) mew-file-max-size)
 		    (null (mew-cache-hit (cons fld msg))))))
-      (insert-file-contents file)
+      (if (mew-folder-imapp fld)
+	  (let (dispproc)
+	    (setq dispproc (start-process mew-prog-imcat
+					  (current-buffer)
+					  mew-prog-imcat
+					  (format "--src=%s" fld) msg))
+	    (mew-set-process-cs dispproc mew-cs-autoconv mew-cs-noconv)
+	    (set-process-filter dispproc 'mew-summary-display-filter)
+	    (set-process-sentinel dispproc 'mew-summary-display-sentinel)
+	    (process-kill-without-query dispproc)
+	    (setq mew-summary-dispbuf-string "")
+	    (setq mew-summary-displaying-folder fld)
+	    (while (eq (process-status dispproc) 'run)
+	      (accept-process-output dispproc)))
+	(insert-file-contents file))
       (mew-header-arrange nodisplay)
-      (if (> (mew-file-size file) mew-file-max-size)
+      (if (and (not (mew-folder-imapp fld))
+	       (> (mew-file-size file) mew-file-max-size))
 	  (message 
 	   (concat "Too large, MIME analysis was skipped. "
 		   "To analyze, type "
@@ -817,6 +853,44 @@
     (set-buffer-modified-p nil)
     hit ;; return value
     ))
+
+(defun mew-summary-display-filter (process string)
+  (save-excursion
+    (set-buffer (process-buffer process))
+    (setq mew-summary-dispbuf-string
+	  (concat mew-summary-dispbuf-string string))
+    (if mew-summary-displaying-folder
+	(if (and (string-match mew-prog-imcat (process-name process))
+		 (string-match "^Password: " mew-summary-dispbuf-string))
+	    (progn
+	      (if (mew-folder-imapp mew-summary-displaying-folder)
+		  (let (host pass)
+		    (string-match
+		     "^\\(%[^:]+\\)\\(:[^/@]+\\)?\\(/[^@]+\\)?@\\(.+\\)$"
+		     mew-summary-displaying-folder)
+		    (setq host (substring mew-summary-displaying-folder
+					  (match-beginning 4) (match-end 4)))
+		    (setq pass (ange-ftp-get-hash-entry host
+							mew-passwd-hashtable))
+		    (process-send-string process (format "%s\n" pass)))
+		(process-send-string
+		 process
+		 (format "%s\n" (mew-read-passwd "Enter password : ")))
+		)
+	      (setq mew-summary-dispbuf-string "")
+	      (setq mew-summary-displaying-folder nil)))
+      (let ((buffer-read-only nil))
+	(goto-char (point-max))
+	(if (and (= (point) (point-min))
+		 (string-match "^\n" mew-summary-dispbuf-string))
+	    (setq mew-summary-dispbuf-string
+		  (substring mew-summary-dispbuf-string 1)))
+	(insert mew-summary-dispbuf-string)
+	(setq mew-summary-dispbuf-string "")))
+    ))
+
+(defun mew-summary-display-sentinel (process event)
+  ())
 
 (defun mew-summary-display-part (fullpart num &optional non-erase execute)
 ;; called in message buffer
diff -aruN mew-1.91-/mew.el mew-1.91+/mew.el
--- mew-1.91-/mew.el	Tue Aug 26 09:59:26 1997
+++ mew-1.91+/mew.el	Sun Sep 14 15:53:28 1997
@@ -286,6 +286,10 @@
 If 'call-process-region' is used, Emacs creates a temporary file
 (probably in /tmp). So bad guys can wiretap the temporary file.")
 
+(defvar mew-imap-path
+  (expand-file-name (concat "~" (user-login-name) "/Mail/IMAP"))
+  "*A directory for saving mew-summary-cache-file for IMAP folder.")
+
 (defvar mew-path-separator "/")
 (defconst mew-home (file-name-as-directory "~"))
 


Mew-dist メーリングリストの案内