From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/68350 Path: news.gmane.org!not-for-mail From: Daiki Ueno Newsgroups: gmane.emacs.gnus.general Subject: Re: nnimap: IMAP mailbox name <-> Gnus newsgroup name Date: Sun, 08 Mar 2009 11:31:36 +0900 Message-ID: <87vdqk3fuf.fsf@broken.deisui.org> References: <87ljrh1tud.fsf@broken.deisui.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1236479549 22173 80.91.229.12 (8 Mar 2009 02:32:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 8 Mar 2009 02:32:29 +0000 (UTC) Cc: ding@gnus.org To: Simon Josefsson Original-X-From: ding-owner+M16789@lists.math.uh.edu Sun Mar 08 03:33:46 2009 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1Lg8pj-0005OM-I6 for ding-account@gmane.org; Sun, 08 Mar 2009 03:33:44 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1Lg8nv-0004uq-RC; Sat, 07 Mar 2009 20:31:51 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1Lg8nu-0004uY-4q for ding@lists.math.uh.edu; Sat, 07 Mar 2009 20:31:50 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtp (Exim 4.69) (envelope-from ) id 1Lg8nq-0004SZ-1V for ding@lists.math.uh.edu; Sat, 07 Mar 2009 20:31:50 -0600 Original-Received: from ti-out-0910.google.com ([209.85.142.184]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1Lg8oB-00059o-00 for ; Sun, 08 Mar 2009 03:32:07 +0100 Original-Received: by ti-out-0910.google.com with SMTP id 28so649333tif.1 for ; Sat, 07 Mar 2009 18:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :references:date:in-reply-to:message-id:user-agent:mime-version :content-type; bh=2fH+QrZxn/ZcY1ht4lceeqJcwdl9zoRV+3FgycPp0kA=; b=ClrAKbNCAuMhJmVDYUMOoYJfKhoHdpTbOjG07so/cjFZNv2ZdxkUXTY0wDDD+uuPJ3 vvv2vQJlE1XhhRupDiGc6dMpKb7LFuc96INCFLtdUxo53+k92m+VkNKDlHkL/cS/BXa9 0N7ICOF5sUH4j0NTbBAl93nuFcs/1DqC73GEA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=TgQyzl95xLvOejzd+cog/0tkmgbtjzv3usR+M5XrCET9+iPert2eiNHhDM6fZfzwsE +w8ATWzZvURUiNXN24WUzTbpj3jSNHHiKSZbJ/bdhNxEuKLIqOIg3uzGsIcaKi7XIAY7 aVCv+Mo0K8ZRfjje81mlapa92EkHogG8jPIbo= Original-Received: by 10.110.69.5 with SMTP id r5mr6435063tia.36.1236479501791; Sat, 07 Mar 2009 18:31:41 -0800 (PST) Original-Received: from broken (g187018.scn-net.ne.jp [202.83.187.18]) by mx.google.com with ESMTPS id i9sm3277436tid.13.2009.03.07.18.31.39 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 07 Mar 2009 18:31:40 -0800 (PST) In-Reply-To: <87ljrh1tud.fsf@broken.deisui.org> (Daiki Ueno's message of "Sat, 07 Mar 2009 19:59:54 +0900") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.91 (gnu/linux) X-Spam-Score: -2.6 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:68350 Archived-At: --=-=-= Daiki Ueno writes: > Presumably nnimap has a confusion of encodings used for IMAP mailbox > names and Gnus group names. The attached is a patch which converts the > Gnus group name to the IMAP mailbox name, and back. Sorry for consecutive posts. The attached patch is more consistent and robuster than the previous one. It does explicitly encode non-ASCII group names in UTF-8 (if available). I've checked this version working with Emacs 22 & 23, and XEmacs 21.4 + Mule-UCS. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=nnimap-convert-mailbox-name.diff Index: lisp/nnimap.el =================================================================== RCS file: /usr/local/cvsroot/gnus/lisp/nnimap.el,v retrieving revision 7.59 diff -u -r7.59 nnimap.el --- lisp/nnimap.el 26 Jan 2009 15:23:27 -0000 7.59 +++ lisp/nnimap.el 8 Mar 2009 02:11:49 -0000 @@ -555,12 +555,12 @@ (or (null (imap-current-mailbox nnimap-server-buffer)) (imap-mailbox-unselect nnimap-server-buffer)))) -(defun nnimap-find-minmax-uid (group &optional examine) +(defun nnimap-find-minmax-uid (mailbox &optional examine) "Find lowest and highest active article number in GROUP. If EXAMINE is non-nil the group is selected read-only." (with-current-buffer nnimap-server-buffer - (when (or (string= group (imap-current-mailbox)) - (imap-mailbox-select group examine)) + (when (or (string= mailbox (imap-current-mailbox)) + (imap-mailbox-select mailbox examine)) (let (minuid maxuid) (when (> (imap-mailbox-get 'exists) 0) (imap-fetch-safe '("1,*" . "1,*:*") "UID" nil 'nouidfetch) @@ -574,12 +574,14 @@ "Make GROUP the current group, and SERVER the current server." (when (nnimap-possibly-change-server server) (with-current-buffer nnimap-server-buffer - (if (or (null group) (imap-current-mailbox-p group)) - imap-current-mailbox - (if (imap-mailbox-select group) + (if (or (null group) (imap-current-mailbox-p + (nnimap-group-to-mailbox group))) + (nnimap-mailbox-to-group imap-current-mailbox) + (if (imap-mailbox-select (nnimap-group-to-mailbox group)) (if (or (nnimap-verify-uidvalidity group (or server nnimap-current-server)) - (zerop (imap-mailbox-get 'exists group)) + (zerop (imap-mailbox-get 'exists + (nnimap-group-to-mailbox group))) t ;; for OGnus to see if ignoring uidvalidity ;; changes has any bad effects. (yes-or-no-p @@ -597,6 +599,20 @@ (setq string (replace-match " " t t string))) string)) +;; We use UTF-8 for the internal group names. +(defun nnimap-group-to-mailbox (group) + "Return the mailbox name corresponding to GROUP." + (if (and group (mm-coding-system-p 'utf-8)) + (mm-decode-coding-string group 'utf-8) + group)) + +;; We use UTF-8 for the internal group names. +(defun nnimap-mailbox-to-group (mailbox) + "Return the group name corresponding to MAILBOX." + (if (and mailbox (mm-coding-system-p 'utf-8)) + (mm-encode-coding-string mailbox 'utf-8) + mailbox)) + ;; Required backend functions (defun nnimap-retrieve-headers-progress () @@ -955,7 +971,8 @@ article))) (when article (gnus-message 10 "nnimap: Fetching (part of) article %d from %s..." - article (or group imap-current-mailbox + article (or group + imap-current-mailbox gnus-newsgroup-name)) (if (not nnheader-callback-function) (with-current-buffer (or to-buffer nntp-server-buffer) @@ -1018,7 +1035,8 @@ (nnimap-before-find-minmax-bugworkaround) (let (info) (cond (fast group) - ((null (setq info (nnimap-find-minmax-uid group t))) + ((null (setq info (nnimap-find-minmax-uid + (nnimap-group-to-mailbox group) t))) (nnheader-report 'nnimap "Could not get active info for %s" group)) (t @@ -1035,7 +1053,8 @@ (let ((old (gnus-gethash-safe (gnus-group-prefixed-name group server) nnimap-mailbox-info))) (list (nth 0 old) (nth 1 old) - (imap-mailbox-status group 'unseen nnimap-server-buffer) + (imap-mailbox-status (nnimap-group-to-mailbox group) 'unseen + nnimap-server-buffer) (nth 3 old))) nnimap-mailbox-info)) @@ -1084,7 +1103,9 @@ (when info (with-current-buffer nntp-server-buffer (insert (format "\"%s\" %d %d y\n" - mbx (or (nth 2 info) 0) + (mm-string-to-multibyte + (nnimap-mailbox-to-group mbx)) + (or (nth 2 info) 0) (max 1 (or (nth 1 info) 1))))))))))) (gnus-message 5 "nnimap: Generating active list%s...done" (if (> (length server) 0) (concat " for " server) "")) @@ -1145,7 +1166,8 @@ 'asyncgroups 'slowgroups) (list group (imap-mailbox-status-asynch - group '(uidvalidity uidnext unseen) + (nnimap-group-to-mailbox group) + '(uidvalidity uidnext unseen) nnimap-server-buffer)))) (dolist (asyncgroup asyncgroups) (let ((group (nth 0 asyncgroup)) @@ -1156,13 +1178,15 @@ (nth 0 (gnus-gethash (gnus-group-prefixed-name group server) nnimap-mailbox-info)) - (imap-mailbox-get 'uidvalidity group + (imap-mailbox-get 'uidvalidity + (nnimap-group-to-mailbox group) nnimap-server-buffer))) (not (string= (nth 1 (gnus-gethash (gnus-group-prefixed-name group server) nnimap-mailbox-info)) - (imap-mailbox-get 'uidnext group + (imap-mailbox-get 'uidnext + (nnimap-group-to-mailbox group) nnimap-server-buffer)))) (push (list group) slowgroups) (insert (nth 3 (gnus-gethash (gnus-group-prefixed-name @@ -1172,14 +1196,19 @@ (if nnimap-retrieve-groups-asynchronous (setq group (car group))) (gnus-message 7 "nnimap: Mailbox %s modified" group) - (imap-mailbox-put 'uidnext nil group nnimap-server-buffer) - (or (member "\\NoSelect" (imap-mailbox-get 'list-flags group - nnimap-server-buffer)) - (let* ((info (nnimap-find-minmax-uid group 'examine)) + (imap-mailbox-put 'uidnext nil (nnimap-group-to-mailbox group) + nnimap-server-buffer) + (or (member "\\NoSelect" (imap-mailbox-get + 'list-flags + (nnimap-group-to-mailbox group) + nnimap-server-buffer)) + (let* ((info (nnimap-find-minmax-uid + (nnimap-group-to-mailbox group) 'examine)) (str (format "\"%s\" %d %d y\n" group (or (nth 2 info) 0) (max 1 (or (nth 1 info) 1))))) - (when (> (or (imap-mailbox-get 'recent group + (when (> (or (imap-mailbox-get 'recent + (nnimap-group-to-mailbox group) nnimap-server-buffer) 0) 0) (push (list (cons group 0)) nnmail-split-history)) @@ -1188,17 +1217,23 @@ (gnus-sethash (gnus-group-prefixed-name group server) (list (or (imap-mailbox-get - 'uidvalidity group nnimap-server-buffer) + 'uidvalidity (nnimap-group-to-mailbox group) + nnimap-server-buffer) (imap-mailbox-status - group 'uidvalidity nnimap-server-buffer)) + (nnimap-group-to-mailbox group) 'uidvalidity + nnimap-server-buffer)) (or (imap-mailbox-get - 'uidnext group nnimap-server-buffer) + 'uidnext (nnimap-group-to-mailbox group) + nnimap-server-buffer) (imap-mailbox-status - group 'uidnext nnimap-server-buffer)) + (nnimap-group-to-mailbox group) 'uidnext + nnimap-server-buffer)) (or (imap-mailbox-get - 'unseen group nnimap-server-buffer) + 'unseen (nnimap-group-to-mailbox group) + nnimap-server-buffer) (imap-mailbox-status - group 'unseen nnimap-server-buffer)) + (nnimap-group-to-mailbox group) 'unseen + nnimap-server-buffer)) str) nnimap-mailbox-info))))))) (gnus-message 5 "nnimap: Checking mailboxes...done") @@ -1268,7 +1303,8 @@ (when (nnimap-possibly-change-group group server) (with-current-buffer nnimap-server-buffer (let (action) - (gnus-message 7 "nnimap: Setting marks in %s..." group) + (gnus-message 7 "nnimap: Setting marks in %s..." + group) (while (setq action (pop actions)) (let ((range (nth 0 action)) (what (nth 1 action)) @@ -1309,7 +1345,8 @@ (imap-message-flags-set (imap-range-to-message-set range) (nnimap-mark-to-flag marks nil t))))))) - (gnus-message 7 "nnimap: Setting marks in %s...done" group)))) + (gnus-message 7 "nnimap: Setting marks in %s...done" + group)))) nil) (defun nnimap-split-fancy () @@ -1396,7 +1433,8 @@ article) (setq removeorig t)) ((imap-message-copy (number-to-string article) - to-group nil 'nocopyuid) + (nnimap-group-to-mailbox to-group) + nil 'nocopyuid) (message "IMAP split moved %s:%s:%d to %s" server inbox article to-group) (setq removeorig t) @@ -1460,8 +1498,10 @@ (deffoo nnimap-request-create-group (group &optional server args) (when (nnimap-possibly-change-server server) - (or (imap-mailbox-status group 'uidvalidity nnimap-server-buffer) - (imap-mailbox-create group nnimap-server-buffer) + (or (imap-mailbox-status (nnimap-group-to-mailbox group) 'uidvalidity + nnimap-server-buffer) + (imap-mailbox-create (nnimap-group-to-mailbox group) + nnimap-server-buffer) (nnheader-report 'nnimap "%S" (imap-error-text nnimap-server-buffer))))) @@ -1594,7 +1634,8 @@ nnimap-current-move-group) (imap-message-copy (number-to-string nnimap-current-move-article) - group 'dontcreate nil + (nnimap-group-to-mailbox group) + 'dontcreate nil nnimap-server-buffer)) (with-current-buffer (current-buffer) (goto-char (point-min)) @@ -1614,25 +1655,30 @@ ;; this 'or' is for Cyrus server bug (or (null (imap-current-mailbox nnimap-server-buffer)) (imap-mailbox-unselect nnimap-server-buffer)) - (imap-message-append group (current-buffer) nil nil + (imap-message-append (nnimap-group-to-mailbox group) + (current-buffer) nil nil nnimap-server-buffer))) (cons group (nth 1 uid)) (nnheader-report 'nnimap (imap-error-text nnimap-server-buffer)))))) (deffoo nnimap-request-delete-group (group force &optional server) (when (nnimap-possibly-change-server server) - (when (string= group (imap-current-mailbox nnimap-server-buffer)) + (when (string= (nnimap-group-to-mailbox group) + (imap-current-mailbox nnimap-server-buffer)) (imap-mailbox-unselect nnimap-server-buffer)) (with-current-buffer nnimap-server-buffer (if force - (or (null (imap-mailbox-status group 'uidvalidity)) - (imap-mailbox-delete group)) + (or (null (imap-mailbox-status (nnimap-group-to-mailbox group) + 'uidvalidity)) + (imap-mailbox-delete (nnimap-group-to-mailbox group))) ;; UNSUBSCRIBE? t)))) (deffoo nnimap-request-rename-group (group new-name &optional server) (when (nnimap-possibly-change-server server) - (imap-mailbox-rename group new-name nnimap-server-buffer))) + (imap-mailbox-rename (nnimap-group-to-mailbox group) + (nnimap-group-to-mailbox new-name) + nnimap-server-buffer))) (defun nnimap-expunge (mailbox server) (when (nnimap-possibly-change-group mailbox server) Index: lisp/utf7.el =================================================================== RCS file: /usr/local/cvsroot/gnus/lisp/utf7.el,v retrieving revision 7.15 diff -u -r7.15 utf7.el --- lisp/utf7.el 22 Jan 2009 07:02:16 -0000 7.15 +++ lisp/utf7.el 8 Mar 2009 02:11:50 -0000 @@ -82,6 +82,10 @@ ;; Avoid versions with BOM. (= 2 (length (encode-coding-string "a" 'utf-16-be)))) 'utf-16-be) + ((and (mm-coding-system-p 'utf-16be) ; Emacs 21.3, Emacs 22 + ;; Avoid versions with BOM. + (= 2 (length (encode-coding-string "a" 'utf-16be)))) + 'utf-16be) ((mm-coding-system-p 'utf-16-be-nosig) ; ? 'utf-16-be-nosig)) "Coding system which encodes big endian UTF-16 without a BOM signature.") --=-=-= Regards, -- Daiki Ueno --=-=-=--