;; Keywords: mail searching
;; Version: 0.5
-;; This file is free software; you can redistribute it and/or modify
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
-;; This file is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; http://www.emacswiki.org/cgi-bin/wiki/GnusMairix
;;
;; The newest version of nnmairix.el can be found at
-;;
+;;
;; http://www.emacswiki.org/cgi-bin/emacs/nnmairix.el
;; For impatient people, here's the setup in a nutshell:
;; * Support of more back ends (nnmh, nnfolder, nnmbox...)?
;; * Maybe use an active file instead of group parameters?
;; * Use "-a" when updating groups which are not newly created
-
+
;;; Changelog:
;;
;; 02/06/2008 - version 0.5
-;;
+;;
;; * New function: nnmairix-goto-original-article. Uses the
;; registry or the mail file path for determining original group.
-;;
+;;
;; * Deal with empty Xref header
;;
;; * Changed summary mode keybindings since the old ones were
;; 18/11/2007 - version 0.3
;;
;; * Fixed bugs when dealing with nnml and native servers
-;;
+;;
;; * Make variables customizable
;;
;; 10/10/2007 - version 0.2
;;; === Keymaps
+(eval-when-compile
+ (when (featurep 'xemacs)
+ ;; The `kbd' macro requires that the `read-kbd-macro' macro is available.
+ (require 'edmacro)))
+
;; Group mode
(defun nnmairix-group-mode-hook ()
"Nnmairix group mode keymap."
server will be this prefix plus a random number. You can delete
unused nnmairix groups on the back end using
`nnmairix-purge-old-groups'."
- :version "23.0"
+ :version "23.1"
:type 'string
:group 'nnmairix)
(defcustom nnmairix-mairix-output-buffer "*mairix output*"
"Buffer used for mairix output."
- :version "23.0"
+ :version "23.1"
:type 'string
:group 'nnmairix)
(defcustom nnmairix-customize-query-buffer "*mairix query*"
"Name of the buffer for customizing Mairix queries."
- :version "23.0"
+ :version "23.1"
:type 'string
:group 'nnmairix)
The default is '-F' and '-Q' for making updates faster. You
should call mairix without these options from time to
time (e.g. via cron job)."
- :version "23.0"
+ :version "23.1"
:type '(repeat string)
:group 'nnmairix)
(defcustom nnmairix-mairix-synchronous-update nil
"Set this to t if you want Emacs to wait for mairix updating the database."
- :version "23.0"
+ :version "23.1"
:type 'boolean
:group 'nnmairix)
article numbers which will produce wrong article counts by
Gnus. This option controls whether nnmairix should rename the
files consecutively."
- :version "23.0"
+ :version "23.1"
:type 'boolean
:group 'nnmairix)
which header contents should be inserted into the editable field
when creating a Mairix query based on the current message (can be
nil for disabling this)."
- :version "23.0"
+ :version "23.1"
:type '(repeat (list
(choice :tag "Field"
(const :tag "none" nil)
(lambda () (select-window (get-largest-window)))
"Function for selecting the window for customizing the mairix query.
The default chooses the largest window in the current frame."
- :version "23.0"
+ :version "23.1"
:type 'function
:group 'nnmairix)
;;; === Internal variables
-(defvar nnmairix-group-regexp
+(defconst nnmairix-group-regexp
(format "%s-\\(.*\\)-[0-9]+" nnmairix-group-prefix)
"Regexp for mairix groups on back end.")
-(defvar nnmairix-valid-backends '(nnimap nnml nnmaildir)
- "Back ends (hopefully...) supported by nnmairix.
+(defconst nnmairix-valid-backends '(nnimap nnml nnmaildir)
+ "Backends supported by nnmairix.
Other backends might or might not work.")
(defvar nnmairix-last-server nil
"Current server.")
;;; === Gnus backend functions
-
+
(nnoo-define-basics nnmairix)
(gnus-declare-backend "nnmairix" 'mail 'address)
"request-scan" folder nnmairix-backend-server)
(if fast
t
- (nnmairix-request-group-with-article-number-correction folder qualgroup)))
+ (nnmairix-request-group-with-article-number-correction
+ folder qualgroup)))
((and (= rval 1)
(save-excursion (set-buffer nnmairix-mairix-output-buffer)
(goto-char (point-min))
t)
nil))
-
+
(nnoo-define-skeleton nnmairix)
(gnus-group-set-parameter group 'query query)
(nnmairix-update-and-clear-marks group)))
(error "This is no nnmairix group"))))
-
+
(defun nnmairix-group-toggle-threads-this-group (&optional threads)
"Toggle threads parameter for this group.
(message "Threads deacitavted for group %s" group))
(nnmairix-update-and-clear-marks group))
(error "This is no nnmairix group"))))
-
+
(defun nnmairix-search (query &optional server threads)
"Sends QUERY to nnmairix backend SERVER, using default its search group.
'nnmairix-sentinel-mairix-update-finished))))))
;; Silence byte-compiler.
-(eval-when-compile
- (defvar gnus-registry-install)
- (autoload 'gnus-registry-fetch-group "gnus-registry"))
+(defvar gnus-registry-install)
+(autoload 'gnus-registry-fetch-group "gnus-registry")
(defun nnmairix-goto-original-article (&optional no-registry)
"Jump to the original group and display article.
;; registry was not available or did not find article
;; so we search again with mairix in raw mode to get filename
(nnmairix-open-server server)
- (setq rval
- (nnmairix-call-mairix-binary-raw
- (split-string nnmairix-mairix-command)
+ (setq rval
+ (nnmairix-call-mairix-binary-raw
+ (split-string nnmairix-mairix-command)
(list (concat "m:" mid))))
(if (zerop rval)
;; determine original group(s) from filename
allgroups)
(forward-line 1))
(if (> (length allgroups) 1)
- (setq group
- (completing-read
- "Message exists in more than one group. Choose: "
+ (setq group
+ (completing-read
+ "Message exists in more than one group. Choose: "
allgroups nil t))
(setq group (car allgroups))))
- (error "Mairix could not find original article. See buffer %s for details"
+ (error "Mairix could not find original article. See buffer %s for details"
nnmairix-mairix-output-buffer))))
(if group
;; show article in summary buffer
(setq maildirflag (string-match ".+\\..+\\..+" filename))
(when maildirflag
(setq path
- (replace-regexp-in-string
+ (replace-regexp-in-string
".*\\(/cur\\|/new\\|/tmp\\)$" "" path t t 1)))
;; we first check nnml and nnmaildir servers
- (setq
+ (setq
group
(catch 'found
(dolist (cur gnus-opened-servers)
(and maildirflag
(eq (caar cur) 'nnmaildir)))
;; get base path from server
- (if maildirflag
- (setq serverbase (cadr (assoc 'directory (car cur))))
+ (if maildirflag
+ (setq serverbase (cadr (assoc 'directory (car cur))))
(setq serverbase (cadr (assoc 'nnml-directory (car cur))))
(when (not serverbase)
(setq serverbase nnml-directory)))
- (setq serverbase (file-name-as-directory
+ (setq serverbase (file-name-as-directory
(expand-file-name serverbase)))
(when (string-match (concat serverbase "\\(.*\\)") path)
;; looks good - rest of the path should be the group
(setq group (replace-match "/" t t group)))
(dolist (cur gnus-opened-servers)
(when (eq (caar cur) 'nnimap)
- (when (gnus-group-entry
+ (when (gnus-group-entry
(gnus-group-prefixed-name group (car cur)))
- (push
+ (push
(gnus-group-prefixed-name group (car cur))
allgroups))))
(if (> (length allgroups) 1)
- (setq group (completing-read
- "Group %s exists on more than one IMAP server. Choose: "
+ (setq group (completing-read
+ "Group %s exists on more than one IMAP server. Choose: "
allgroups nil t))
(setq group (car allgroups))))
group))
(defun nnmairix-request-group-with-article-number-correction (folder qualgroup)
"Request FOLDER on backend for nnmairix QUALGROUP and article number correction."
(save-excursion
- (nnmairix-call-backend
- "request-group" folder nnmairix-backend-server)
+ (nnmairix-call-backend "request-group" folder nnmairix-backend-server)
(set-buffer nnmairix-mairix-output-buffer)
(goto-char (point-min))
(re-search-forward "^Matched.*messages")
(set-buffer nntp-server-buffer)
(goto-char (point-min))
(nnheader-message 7 "nnmairix: Rewriting headers...")
- (mapcar
- (function
- (lambda (article)
- (when (or (looking-at (number-to-string article))
- (nnheader-find-nov-line article))
- (setq cur (nnheader-parse-nov))
- (when corr
- (setq article (+ (mail-header-number cur) numc))
- (mail-header-set-number cur article))
- (setq xref (mail-header-xref cur))
- (when (and (stringp xref)
- (string-match (format "[ \t]%s:[0-9]+" backendgroup) xref))
- (setq xref (replace-match (format " %s:%d" mairixgroup article) t nil xref))
- (mail-header-set-xref cur xref))
- (set-buffer buf)
- (nnheader-insert-nov cur)
- (set-buffer nntp-server-buffer)
- (when (not (eobp))
- (forward-line 1)))))
+ (mapc
+ (lambda (article)
+ (when (or (looking-at (number-to-string article))
+ (nnheader-find-nov-line article))
+ (setq cur (nnheader-parse-nov))
+ (when corr
+ (setq article (+ (mail-header-number cur) numc))
+ (mail-header-set-number cur article))
+ (setq xref (mail-header-xref cur))
+ (when (and (stringp xref)
+ (string-match (format "[ \t]%s:[0-9]+" backendgroup) xref))
+ (setq xref (replace-match (format " %s:%d" mairixgroup article) t nil xref))
+ (mail-header-set-xref cur xref))
+ (set-buffer buf)
+ (nnheader-insert-nov cur)
+ (set-buffer nntp-server-buffer)
+ (when (not (eobp))
+ (forward-line 1))))
articles)
(nnheader-message 7 "nnmairix: Rewriting headers... done")
(kill-buffer nntp-server-buffer)
(when (gnus-group-jump-to-group group)
(gnus-group-get-new-news-this-group)))
(error "Nnmairix-update-and-clear-marks - Called with non-nnmairix group"))))
-
+
(defun nnmairix-sentinel-mairix-update-finished (proc status)
"Sentinel for mairix update process PROC with STATUS."
(gnus-summary-exit))
(pop-to-buffer gnus-group-buffer)
(gnus-group-jump-to-group group)
- (gnus-summary-read-group group 1 t)
+ (gnus-summary-read-group group 1 t)
(gnus-summary-refer-article mid)
(gnus-summary-limit-to-headers (format "message-id: <%s>" mid))
(gnus-summary-select-article)
(mapcar
(function
(lambda (field)
- (list (caddr field)
+ (list (car (cddr field))
(if (car field)
(nnmairix-replace-illegal-chars
(gnus-fetch-field (car field)))
nil))))
nnmairix-widget-fields-list))))
-
+
(defun nnmairix-widget-search (&optional mvalues)
"Create mairix query interactively using graphical widgets.
(dolist (cur nnmairix-widget-fields-list)
;; See if checkbox is checked
(when (widget-value
- (cadr (assoc (concat "c" (caddr cur)) widgets)))
+ (cadr (assoc (concat "c" (car (cddr cur))) widgets)))
;; create query for the field
(push
(concat
":"
(nnmairix-replace-illegal-chars
(widget-value
- (cadr (assoc (concat "e" (caddr cur)) widgets)))))
+ (cadr (assoc (concat "e" (car (cddr cur))) widgets)))))
query)))
;; Flags
(when (member 'flags nnmairix-widget-other)
(mapc
(function
(lambda (field)
- (setq field (caddr field))
+ (setq field (car (cddr field)))
(setq ret
(nconc
(list