1 ;;; nnmairix.el --- Mairix back end for Gnus, the Emacs newsreader
3 ;; Copyright (C) 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: David Engster <dengste@eml.cc>
6 ;; Keywords: mail searching
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; THIS IS BETA SOFTWARE! This back end should not mess up or
27 ;; even delete your mails, but having a backup is always a good idea.
29 ;; This is a back end for using the mairix search engine with
30 ;; Gnus. Mairix is a tool for searching words in locally stored
31 ;; mail. Mairix is very fast which allows using it efficiently for
32 ;; "smart folders", e.g. folders which are associated with search
33 ;; queries. Of course, you can also use this back end just for
34 ;; calling mairix with some search query.
36 ;; Mairix is written by Richard Curnow. More information can be found at
37 ;; http://www.rpcurnow.force9.co.uk/mairix/
39 ;; For details about setting up mairix&Gnus&nnmairix.el, look at the
42 ;; http://www.emacswiki.org/cgi-bin/wiki/GnusMairix
44 ;; The newest version of nnmairix.el can be found at
46 ;; http://www.emacswiki.org/cgi-bin/emacs/nnmairix.el
48 ;; For impatient people, here's the setup in a nutshell:
50 ;; This back end requires an installed mairix binary which is
51 ;; configured to index your mail folder. You don't have to specify a
52 ;; search folder (but it does no harm, either). Visit the man page of
53 ;; mairix and mairixrc for details.
55 ;; Put nnmairix.el into your search path and "(require 'nnmarix)" into
56 ;; your .gnus. Then call nnmairix-create-default-group (or 'G b
57 ;; c'). This function will ask for all necessary information to create
58 ;; a mairix server in Gnus with the default search folder. This
59 ;; default search folder will be used for all temporary searches: call
60 ;; nnmairix-search ('G b s') and enter a mairix query (like
61 ;; f:test@example.com). To create a mairix group for one specific
62 ;; search query, use 'G b g'. See the emacswiki or the source for more
65 ;; Commentary on the code: nnmairix sits between Gnus and the "real"
66 ;; back end which handles the mail (currently nnml, nnimap and
67 ;; nnmaildir were tested). I know this is all a bit hacky, but so far
68 ;; it works for me. This is the first back end I've written for Gnus,
69 ;; so I'd appreciate any comments, suggestions, bug reports (and, of
70 ;; course, patches) for improving nnmairix.
72 ;; nnmairix does not use an active file, since I wanted to contain the
73 ;; back end "inside Gnus" as much as possible without the need of an
74 ;; external file. It stores the query/folder information in the group
75 ;; parameters instead. This also implies that once you kill a mairix
76 ;; group, it's gone for good. I don't think that this is really
77 ;; problematic, since I don't see the need in unsubscribing and
78 ;; re-subscribing search groups
80 ;; Every mairix server is "responsible" for one mairix installation,
81 ;; i.e. you can have several mairix servers for different mairix
82 ;; configurations. Not that I think anyone will actually do this, but
83 ;; I thought it would be a "nice to have feature"...
86 ;; * Mairix does only support us-ascii characters.
88 ;; TODO/MISSING FEATURES:
89 ;; * Support of more back ends (nnmh, nnfolder, nnmbox...)?
90 ;; * Maybe use an active file instead of group parameters?
91 ;; * Maybe use "-a" when updating groups which are not newly created?
94 ;; 05/30/2008 - version 0.6
96 ;; * It is now possible to propagate marks from the nnmairix groups
97 ;; to the original messages (and for maildir also vice versa). See
98 ;; the docs for details on this feature - it's pretty delicate
99 ;; and currently needs a patched mairix binary to work smoothly.
101 ;; * Keep messages in nnmairix groups always read/unread
102 ;; (bound to 'G b r').
104 ;; * Recreate back end folder for nnmairix groups in case you
105 ;; somehow get wrong article counts (bound to 'G b d').
107 ;; * New group parameter 'allow-fast'. Toggling of parameter bound
108 ;; to 'G b a'. The default is nil, meaning that the group will
109 ;; always be updated with a mairix search, even when only entered.
111 ;; * More/Better use of the registry (if available). Can now also
112 ;; deal with duplicate messages in different groups.
114 ;; 02/06/2008 - version 0.5
116 ;; * New function: nnmairix-goto-original-article. Uses the
117 ;; registry or the mail file path for determining original group.
119 ;; * Deal with empty Xref header
121 ;; * Changed summary mode keybindings since the old ones were
124 ;; (Thanks to Tassilo Horn and Ted Zlatanov for their help)
126 ;; 01/07/2008 - version 0.4
128 ;; * New/fixed doc strings and code cleanup.
130 ;; 11/18/2007 - version 0.3
132 ;; * Fixed bugs when dealing with nnml and native servers
134 ;; * Make variables customizable
136 ;; 10/10/2007 - version 0.2
138 ;; * Use nnml-directory/directory server variables for nnml and
139 ;; nnmaildir back ends as path for search folders. This way it
140 ;; becomes independent of 'base' setting in .mairixirc (but not for
143 ;; * As a result: Changed nnmairix-backend-to-server so that user
144 ;; is asked when more than one nnmairix server exists and we do not
145 ;; know which one is responsible for current back end.
147 ;; * Rename files when using nnml back ends so that there are no
148 ;; holes in article numbers. This should fix all problems regarding
149 ;; wrong article counts with nnml.
151 ;; * More commands for creating queries (using widgets or the
154 ;; * Fixed bug in nnmairix-create-search-group-from-message
156 ;; * Changed copyright to FSF
158 ;; (Thanks to Georg C. F. Greve and Bastien for suggestions and
161 ;; 10/03/2007 - version 0.1 - first release
167 (require 'gnus-group)
173 (nnoo-declare nnmairix)
178 (when (featurep 'xemacs)
179 ;; The `kbd' macro requires that the `read-kbd-macro' macro is available.
183 (defun nnmairix-group-mode-hook ()
184 "Nnmairix group mode keymap."
185 (define-key gnus-group-mode-map
186 (kbd "G b") (make-sparse-keymap))
187 (define-key gnus-group-mode-map
188 (kbd "G b g") 'nnmairix-create-search-group)
189 (define-key gnus-group-mode-map
190 (kbd "G b c") 'nnmairix-create-server-and-default-group)
191 (define-key gnus-group-mode-map
192 (kbd "G b q") 'nnmairix-group-change-query-this-group)
193 (define-key gnus-group-mode-map
194 (kbd "G b t") 'nnmairix-group-toggle-threads-this-group)
195 (define-key gnus-group-mode-map
196 (kbd "G b u") 'nnmairix-update-database)
197 (define-key gnus-group-mode-map
198 (kbd "G b s") 'nnmairix-search)
199 (define-key gnus-group-mode-map
200 (kbd "G b i") 'nnmairix-search-interactive)
201 (define-key gnus-group-mode-map
202 (kbd "G b m") 'nnmairix-widget-search)
203 (define-key gnus-group-mode-map
204 (kbd "G b p") 'nnmairix-group-toggle-propmarks-this-group)
205 (define-key gnus-group-mode-map
206 (kbd "G b r") 'nnmairix-group-toggle-readmarks-this-group)
207 (define-key gnus-group-mode-map
208 (kbd "G b d") 'nnmairix-group-delete-recreate-this-group)
209 (define-key gnus-group-mode-map
210 (kbd "G b a") 'nnmairix-group-toggle-allowfast-this-group)
211 (define-key gnus-group-mode-map
212 (kbd "G b o") 'nnmairix-propagate-marks))
215 (defun nnmairix-summary-mode-hook ()
216 "Nnmairix summary mode keymap."
217 (define-key gnus-summary-mode-map
218 (kbd "$ t") 'nnmairix-search-thread-this-article)
219 (define-key gnus-summary-mode-map
220 (kbd "$ f") 'nnmairix-search-from-this-article)
221 (define-key gnus-summary-mode-map
222 (kbd "$ m") 'nnmairix-widget-search-from-this-article)
223 (define-key gnus-summary-mode-map
224 (kbd "$ g") 'nnmairix-create-search-group-from-message)
225 (define-key gnus-summary-mode-map
226 (kbd "$ o") 'nnmairix-goto-original-article)
227 (define-key gnus-summary-mode-map
228 (kbd "$ u") 'nnmairix-remove-tick-mark-original-article))
230 (add-hook 'gnus-group-mode-hook 'nnmairix-group-mode-hook)
231 (add-hook 'gnus-summary-mode-hook 'nnmairix-summary-mode-hook)
234 ;; (defun nnmairix-initalize (&optional force)
236 ;; (if (not (or (file-readable-p "~/.mairixrc")
238 ;; (message "No file `~/.mairixrc', skipping nnmairix setup")
239 ;; (add-hook 'gnus-group-mode-hook 'nnmairix-group-mode-hook)
240 ;; (add-hook 'gnus-summary-mode-hook 'nnmairix-summary-mode-hook)))
242 ;; Customizable stuff
244 (defgroup nnmairix nil
245 "Back end for the Mairix mail search engine."
248 (defcustom nnmairix-group-prefix "zz_mairix"
249 "Prefix for mairix search groups on back end server.
250 nnmairix will create these groups automatically on the back end
251 server for each nnmairix search group. The name on the back end
252 server will be this prefix plus a random number. You can delete
253 unused nnmairix groups on the back end using
254 `nnmairix-purge-old-groups'."
259 (defcustom nnmairix-mairix-output-buffer "*mairix output*"
260 "Buffer used for mairix output."
265 (defcustom nnmairix-customize-query-buffer "*mairix query*"
266 "Name of the buffer for customizing Mairix queries."
271 (defcustom nnmairix-mairix-update-options '("-F" "-Q")
272 "Options when calling mairix for updating the database.
273 The default is '-F' and '-Q' for making updates faster. You
274 should call mairix without these options from time to
275 time (e.g. via cron job)."
277 :type '(repeat string)
280 (defcustom nnmairix-mairix-search-options '("-Q")
281 "Options when calling mairix for searching.
282 The default is '-Q' for making searching faster."
284 :type '(repeat string)
287 (defcustom nnmairix-mairix-synchronous-update nil
288 "Set this to t if you want Emacs to wait for mairix updating the database."
293 (defcustom nnmairix-rename-files-for-nnml t
294 "Rename nnml mail files so that they are consecutively numbered.
295 When using nnml as back end, mairix might produce holes in the
296 article numbers which will produce wrong article counts by
297 Gnus. This option controls whether nnmairix should rename the
298 files consecutively."
303 (defcustom nnmairix-widget-fields-list
304 '(("from" "f" "From") ("to" "t" "To") ("cc" "c" "Cc")
305 ("subject" "s" "Subject") ("to" "tc" "To or Cc")
306 ("from" "a" "Address") (nil "b" "Body") (nil "n" "Attachment")
307 ("Message-ID" "m" "Message ID") (nil "s" "Size") (nil "d" "Date"))
308 "Fields that should be editable during interactive query customization.
310 Header, corresponding mairix command and description for editable
311 fields in interactive query customization. The header specifies
312 which header contents should be inserted into the editable field
313 when creating a Mairix query based on the current message (can be
314 nil for disabling this)."
318 (const :tag "none" nil)
319 (const :tag "From" "from")
320 (const :tag "To" "to")
321 (const :tag "Cc" "cc")
322 (const :tag "Subject" "subject")
323 (const :tag "Message ID" "Message-ID"))
324 (string :tag "Command")
325 (string :tag "Description")))
328 (defcustom nnmairix-widget-select-window-function
329 (lambda () (select-window (get-largest-window)))
330 "Function for selecting the window for customizing the mairix query.
331 The default chooses the largest window in the current frame."
336 (defcustom nnmairix-propagate-marks-upon-close t
337 "Flag if marks should be propagated upon closing a group.
338 The default of this variable is t. If set to 'ask, the
339 user will be asked if the flags should be propagated when the
340 group is closed. If set to nil, the user will have to manually
341 call 'nnmairix-propagate-marks'."
343 :type '(choice (const :tag "always" t)
344 (const :tag "ask" 'ask)
345 (const :tag "never" nil))
348 (defcustom nnmairix-propagate-marks-to-nnmairix-groups nil
349 "Flag if marks from original articles should be seen in nnmairix groups.
350 The default is nil since it will only work if the articles are in
351 maildir format and NOT managed by the nnmaildir back end but
352 e.g. an IMAP server (which stores the marks in the maildir file
353 name). You may safely set this to t for testing - the worst that
354 can happen are wrong marks in nnmairix groups."
359 (defcustom nnmairix-only-use-registry nil
360 "Use only the registry for determining original group(s).
361 If set to t, nnmairix will only use the registry for determining
362 the original group(s) of an article (which is also necessary for
363 propapagting marks). If set to nil, it will also try to determine
364 the group from an additional mairix search which might be slow
365 when propagating lots of marks."
370 (defcustom nnmairix-allowfast-default nil
371 "Whether fast entering should be the default for nnmairix groups.
372 You may set this to t to make entering the group faster, but note that
373 this might lead to problems, especially when used with marks propagation."
378 ;; ==== Other variables
380 (defvar nnmairix-widget-other
382 "Other editable mairix commands when using customization widgets.
383 Currently there are 'threads and 'flags.")
385 (defvar nnmairix-interactive-query-parameters
386 '((?f "from" "f" "From") (?t "to" "t" "To") (?c "to" "tc" "To or Cc")
387 (?a "from" "a" "Address") (?s "subject" "s" "Subject") (?b nil "b" "Body")
388 (?d nil "d" "Date") (?n nil "n" "Attachment"))
389 "Things that should be editable during interactive query generation.
390 Every list element consists of the following entries: Keystroke,
391 message field (if any), mairix command and description.")
393 (defvar nnmairix-delete-and-create-on-change '(nnimap nnmaildir nnml)
394 "Controls on which back ends groups should be deleted and re-created.
395 This variable is a list of back ends where the search group
396 should be completely deleted and re-created when the query or
397 thread parameter changes. The default is to this for all
398 currently supported back ends. It usually also corrects the
399 problem of \"holes\" in the article numbers which often lead to a
400 wrong count of total articles shown by Gnus.")
402 ;;; === Server variables
404 (defvoo nnmairix-backend nil
405 "Back end where mairix stores its searches.")
407 (defvoo nnmairix-backend-server nil
408 "Name of the server where mairix stores its searches.")
410 (defvoo nnmairix-mairix-command "mairix"
411 "Command to call mairix for this nnmairix server.")
413 (defvoo nnmairix-hidden-folders nil
414 "Set this to t if the back end server uses hidden directories for
415 its maildir mail folders (e.g. the Dovecot IMAP server or mutt).")
417 (defvoo nnmairix-default-group nil
418 "Default search group. This is the group which is used for all
419 temporary searches, e.g. nnmairix-search.")
421 ;;; === Internal variables
423 (defconst nnmairix-group-regexp
424 (format "%s-\\(.*\\)-[0-9]+" nnmairix-group-prefix)
425 "Regexp for mairix groups on back end.")
427 (defconst nnmairix-valid-backends '(nnimap nnml nnmaildir)
428 "Back ends supported by nnmairix.
429 Other back ends might or might not work.")
431 (defvar nnmairix-last-server nil
432 "Last chosen server.")
434 (defvar nnmairix-current-server nil
437 (defvar nnmairix-marks-cache nil
438 "Cache for marks which should be set upon closing current group.")
440 (defvar nnmairix-version-output nil
441 "Version string of mairix binary.")
443 ;;; === Gnus back end functions
445 (nnoo-define-basics nnmairix)
447 (gnus-declare-backend "nnmairix" 'mail 'address)
449 (deffoo nnmairix-open-server (server &optional definitions)
450 ;; just set server variables
451 (setq nnmairix-current-server server)
452 (nnoo-change-server 'nnmairix server definitions))
454 (deffoo nnmairix-request-group (group &optional server fast)
455 ;; Call mairix and request group on back end server
456 (when server (nnmairix-open-server server))
457 (let* ((qualgroup (if server
458 (gnus-group-prefixed-name group (list 'nnmairix server))
460 (folder (gnus-group-get-parameter qualgroup 'folder))
461 (allowfast (gnus-group-get-parameter qualgroup 'allow-fast))
462 (query (gnus-group-get-parameter qualgroup 'query t))
463 (threads (gnus-group-get-parameter qualgroup 'threads))
464 (backendmethod (gnus-server-to-method
465 (format "%s:%s" (symbol-name nnmairix-backend)
466 nnmairix-backend-server)))
467 rval mfolder folderpath args)
470 ;; No folder parameter -> error
471 (nnheader-report 'nnmairix "Check folder parameter for group %s" group)
474 ;; No query -> return empty group
476 (set-buffer nntp-server-buffer)
478 (insert (concat "211 0 1 0 " group))
481 ;; For maildir++ folders: create a hidden directory (prepend dot)
482 (setq mfolder (if (and nnmairix-hidden-folders
483 (not (string-match "^\\." folder)))
486 ;; For nnml and nnmaildir, precede mfolder with directory where mail
487 ;; is actually stored so that it's independent of 'base' setting
489 (when (eq nnmairix-backend 'nnml)
490 (setq folderpath (cadr (assoc 'nnml-directory backendmethod)))
491 ;; if nnml-directory is not explicitly set, use global value
492 (when (not folderpath)
493 (setq folderpath nnml-directory)))
494 (when (eq nnmairix-backend 'nnmaildir)
496 (cadr (assoc 'directory backendmethod))))
500 (file-name-as-directory
504 ;; If (not fast), call Mairix binary
505 ;; recreate underlying folder on the back end
507 (if (and fast allowfast)
509 (nnmairix-call-mairix-binary
510 (split-string nnmairix-mairix-command)
511 mfolder query threads)))
512 ;; Check return value
514 ((zerop rval) ; call was succesful
515 (nnmairix-call-backend
516 "open-server" nnmairix-backend-server)
517 ;; If we're dealing with nnml, rename files
518 ;; consecutively and make new active file for this
520 (when (eq nnmairix-backend 'nnml)
521 (when nnmairix-rename-files-for-nnml
522 (nnmairix-rename-files-consecutively mfolder))
523 (nnml-generate-nov-databases-directory mfolder))
524 (nnmairix-call-backend
525 "request-scan" folder nnmairix-backend-server)
526 (if (and fast allowfast)
528 (nnmairix-request-group-with-article-number-correction
531 (save-excursion (set-buffer nnmairix-mairix-output-buffer)
532 (goto-char (point-min))
533 (looking-at "^Matched 0 messages")))
534 ;; No messages found -> return empty group
535 (nnheader-message 5 "Mairix: No matches found.")
536 (set-buffer nntp-server-buffer)
538 (insert (concat "211 0 1 0 " group))
540 ;; Everything else is an error
543 'nnmairix "Error running marix. See buffer %s for details"
544 nnmairix-mairix-output-buffer)
548 (deffoo nnmairix-request-create-group (group &optional server args)
549 (let ((qualgroup (if server (gnus-group-prefixed-name group (list 'nnmairix server))
554 (when server (nnmairix-open-server server))
555 (gnus-group-add-parameter qualgroup '(query . nil))
556 (gnus-group-add-parameter qualgroup '(threads . nil))
558 (setq count (1+ count))
559 (setq groupname (format "%s-%s-%s" nnmairix-group-prefix group
560 (number-to-string count)))
561 (setq exist (nnmairix-call-backend
562 "request-group" groupname nnmairix-backend-server)))
563 (nnmairix-call-backend
564 "request-create-group" groupname nnmairix-backend-server)
565 (gnus-group-add-parameter qualgroup '(folder . nil))
566 (when nnmairix-allowfast-default
567 (gnus-group-add-parameter qualgroup '(allow-fast . t)))
568 (gnus-group-set-parameter qualgroup 'folder groupname))
572 (deffoo nnmairix-retrieve-headers (articles group &optional server fetch-old)
573 (when server (nnmairix-open-server server))
574 (let* ((folder (nnmairix-get-backend-folder group server))
575 (corr (nnmairix-get-numcorr group server))
579 (not (zerop (cadr corr)))
580 (numberp (car articles)))
581 (setq numcorr (cadr corr))
584 (lambda (arg) (- arg numcorr))
586 (setq rval (nnmairix-call-backend
587 "retrieve-headers" articles folder nnmairix-backend-server fetch-old))
589 (nnmairix-replace-group-and-numbers articles folder group numcorr)
592 (deffoo nnmairix-request-article (article &optional group server to-buffer)
593 (when server (nnmairix-open-server server))
594 (let ((folder (nnmairix-get-backend-folder group server))
595 (corr (nnmairix-get-numcorr group server)))
599 (not (zerop (cadr corr))))
600 (setq article (- article (cadr corr))))
601 (nnmairix-call-backend
602 "request-article" article folder nnmairix-backend-server to-buffer))
605 (deffoo nnmairix-request-list (&optional server)
606 (when server (nnmairix-open-server server))
607 (if (nnmairix-call-backend "request-list" nnmairix-backend-server)
608 (let (cpoint cur qualgroup folder)
610 (set-buffer nntp-server-buffer)
611 (goto-char (point-min))
612 (setq cpoint (point))
613 (while (re-search-forward nnmairix-group-regexp (point-max) t)
614 (setq cur (match-string 1)
615 qualgroup (gnus-group-prefixed-name cur
616 (list 'nnmairix server)))
617 (if (and (gnus-group-entry qualgroup)
618 (string= (match-string 0)
619 (gnus-group-get-parameter qualgroup 'folder)))
622 (delete-region cpoint (point-at-bol))
624 (setq cpoint (point)))
626 (delete-region cpoint (point-max)))
630 (deffoo nnmairix-request-set-mark (group actions &optional server)
632 (nnmairix-open-server server))
633 (let* ((qualgroup (gnus-group-prefixed-name group (list 'nnmairix nnmairix-current-server)))
634 (propmarks (gnus-group-get-parameter qualgroup 'propmarks))
635 (propto (gnus-group-get-parameter qualgroup 'propto t))
636 (corr (nnmairix-get-numcorr group server))
637 (folder (nnmairix-get-backend-folder group server)))
639 (dolist (cur actions)
640 (let ((type (nth 1 cur))
641 (cmdmarks (nth 2 cur))
642 (range (gnus-uncompress-range (nth 0 cur)))
643 mid ogroup number method temp)
645 (not (zerop (cadr corr))))
646 (setq range (mapcar (lambda (arg)
650 (nnheader-message 7 "nnmairix: Setting marks...")
651 (dolist (article range)
652 ;; get article (header) and extract message id
653 ;; we try to determine as many original articles as possible
655 (nnmairix-call-backend "open-server" nnmairix-backend-server)
656 (unless (gnus-request-head
658 (gnus-group-prefixed-name
660 (list nnmairix-backend nnmairix-backend-server)))
662 3 "Unable to set mark: couldn't fetch article header for article number %d"
664 (throw 'problem nil))
665 (set-buffer nntp-server-buffer)
666 (goto-char (point-min))
667 (let ((case-fold-search t))
668 (re-search-forward "^message-id:.*\\(<.+>\\)" nil t))
669 (setq mid (match-string 1))
672 3 "Unable to set mark: article number %d has no message-id header"
674 (throw 'problem nil))
675 ;; get original group. First try registry, then file path
677 (nnmairix-determine-original-group-from-registry mid))
679 nnmairix-only-use-registry)
681 (nnmairix-determine-original-group-from-path
682 mid nnmairix-current-server))
683 ;; if available and allowed, add this entry to the registry
684 (when (and (boundp 'gnus-registry-install)
685 gnus-registry-install)
687 (unless (gnus-parameter-registry-ignore cur)
688 (gnus-registry-add-group mid cur)))))
691 3 "Unable to set mark: couldn't find original group for %s" mid)
692 (throw 'problem nil))
693 ;; store original groups with mid's. We cannot get
694 ;; the article number immediately since this would
695 ;; generate problems with maildir (articles might
696 ;; get moved from /new to /cur and further marks
697 ;; could then not be set)
699 (setq temp (assoc cur
700 nnmairix-marks-cache))
702 (nconc temp (list (list mid type cmdmarks)))
703 (push (list cur (list mid type cmdmarks))
704 nnmairix-marks-cache)))))
705 (nnheader-message 7 "nnmairix: Setting marks... done")))))))
707 (deffoo nnmairix-close-group (group &optional server)
709 (nnmairix-open-server server))
710 (let* ((qualgroup (gnus-group-prefixed-name group (list 'nnmairix nnmairix-current-server)))
711 (propmarks (gnus-group-get-parameter qualgroup 'propmarks))
714 nnmairix-marks-cache)
715 (when (or (eq nnmairix-propagate-marks-upon-close t)
716 (and (eq nnmairix-propagate-marks-upon-close 'ask)
717 (y-or-n-p "Propagate marks to original articles? ")))
719 (set-buffer gnus-group-buffer)
720 (nnmairix-propagate-marks)
721 ;; update mairix group
722 (gnus-group-jump-to-group qualgroup)
723 (gnus-group-get-new-news-this-group))))))
725 (deffoo nnmairix-request-update-info (group info &optional server)
726 ;; propagate info from underlying IMAP folder to nnmairix group
727 ;; This is currently experimental and must be explicitly activated
728 ;; with nnmairix-propagate-marks-to-nnmairix-group
730 (nnmairix-open-server server))
731 (let* ((qualgroup (gnus-group-prefixed-name
733 (list 'nnmairix nnmairix-current-server)))
734 (readmarks (gnus-group-get-parameter qualgroup 'readmarks))
735 (propmarks (gnus-group-get-parameter qualgroup 'propmarks))
736 (folder (nnmairix-get-backend-folder group server))
737 (corr (nnmairix-get-numcorr group server))
738 (docorr (and corr (not (zerop (cadr corr)))))
739 (folderinfo `(,group 1 ((1 . 1))))
742 nnmairix-propagate-marks-to-nnmairix-groups)
743 ;; these groups are not subscribed, so we have to ask the back end directly
744 (if (eq nnmairix-backend 'nnimap)
745 (nnimap-request-update-info-internal folder folderinfo nnmairix-backend-server)
746 (nnmairix-call-backend "request-update-info" folder folderinfo nnmairix-backend-server))
747 ;; set range of read articles
752 `(lambda (x) (+ x ,(cadr corr)))
753 (gnus-info-read folderinfo))
754 (gnus-info-read folderinfo)))
759 (mapcar (lambda (cur)
763 `(lambda (x) (+ x ,(cadr corr)))
765 (gnus-info-marks folderinfo))
766 (gnus-info-marks folderinfo))))
767 (when (eq readmarks 'unread)
768 (gnus-info-set-read info nil))
769 (when (eq readmarks 'read)
770 (gnus-info-set-read info (gnus-active qualgroup))))
773 (nnoo-define-skeleton nnmairix)
776 ;;; === Interactive functions
778 (defun nnmairix-create-search-group (server group query threads)
779 "Create on SERVER nnmairix search group GROUP with QUERY.
780 If THREADS is t, include whole threads from found messages. If
781 called interactively, user will be asked for parameters."
784 (gnus-server-to-method (car (nnmairix-get-server)))
785 (read-string "Group name: ")
786 (read-string "Query: ")
787 (y-or-n-p "Include threads? ")))
788 (when (and (stringp query)
789 (string-match "\\s-" query))
790 (setq query (split-string query)))
791 (when (not (listp query))
792 (setq query (list query)))
793 (when (and server group query)
795 (let ((groupname (gnus-group-prefixed-name group server))
797 (set-buffer gnus-group-buffer)
798 (gnus-group-make-group group server)
799 (gnus-group-set-parameter groupname 'query query)
800 (gnus-group-set-parameter groupname 'threads threads)
801 (nnmairix-update-and-clear-marks groupname)))))
803 (defun nnmairix-search-interactive ()
804 "Create mairix search interactively with the minibuffer."
806 (let ((char-header nnmairix-interactive-query-parameters)
807 header finished query achar)
808 (while (not finished)
810 (message "Query (%s): " (nnmairix-create-message-line-for-search))
811 (setq achar (read-char))
812 (when (not (assoc achar char-header))
814 (setq header (read-string
815 (concat "Match " (nth 3 (assoc achar char-header)) " on: ")))
816 (push (concat (nth 2 (assoc achar char-header)) ":" header) query)
817 (setq finished (not (y-or-n-p "Add another search query? "))
820 (mapconcat 'identity query " ")
821 (car (nnmairix-get-server))
822 (y-or-n-p "Include whole threads? "))))
824 (defun nnmairix-create-search-group-from-message ()
825 "Interactively create search group with query based on current message."
827 (let ((char-header nnmairix-interactive-query-parameters)
828 (server (nnmairix-backend-to-server gnus-current-select-method))
829 query achar header finished group threads cq)
830 (when (or (not (gnus-buffer-live-p gnus-article-buffer))
831 (not (gnus-buffer-live-p gnus-summary-buffer)))
832 (error "No article or summary buffer"))
834 (error "No nnmairix server found for back end %s:%s"
835 (symbol-name (car gnus-current-select-method))
836 (nth 1 gnus-current-select-method)))
837 (while (not finished)
839 (gnus-summary-toggle-header 1)
841 (message "Query (%s): " (nnmairix-create-message-line-for-search))
842 (setq achar (read-char))
843 (when (not (assoc achar char-header))
845 (set-buffer gnus-article-buffer)
847 (when (setq cq (nth 1 (assoc achar char-header)))
849 (nnmairix-replace-illegal-chars
850 (gnus-fetch-field (nth 1 (assoc achar char-header))))))
851 (setq header (read-string
852 (concat "Match " (nth 3 (assoc achar char-header)) " on: ")
854 (push (concat (nth 2 (assoc achar char-header)) ":" header) query)
855 (setq finished (not (y-or-n-p "Add another search query? "))
857 (setq threads (y-or-n-p "Include whole threads? "))
858 (setq group (read-string "Group name: "))
859 (set-buffer gnus-summary-buffer)
860 (message "Creating group %s on server %s with query %s." group
861 (gnus-method-to-server server) (mapconcat 'identity query " "))
862 (nnmairix-create-search-group server group query threads)))
864 (defun nnmairix-create-server-and-default-group ()
865 "Interactively create new nnmairix server with default search group.
866 All necessary information will be queried from the user."
868 (let* ((name (read-string "Name of the mairix server: "))
869 (server (completing-read "Back end server (TAB for completion): "
870 (nnmairix-get-valid-servers)))
871 (mairix (read-string "Command to call mairix: " "mairix"))
872 (defaultgroup (read-string "Default search group: "))
873 (backend (symbol-name (car (gnus-server-to-method server))))
874 (servername (nth 1 (gnus-server-to-method server)))
875 (hidden (and (string-match "^nn\\(imap\\|maildir\\)$" backend)
877 "Does the back end server work with maildir++ (i.e. hidden directories)? ")))
880 (apply (intern (format "%s-%s" backend "open-server"))
884 (string-match "^\\." defaultgroup))
885 (setq defaultgroup (substring defaultgroup 1)))
886 ;; Create default search group
887 (gnus-group-make-group
888 defaultgroup (list 'nnmairix name (list 'nnmairix-backend (intern backend))
889 (list 'nnmairix-backend-server servername)
890 (list 'nnmairix-mairix-command mairix)
891 (list 'nnmairix-hidden-folders hidden)
892 (list 'nnmairix-default-group defaultgroup)))))
894 (defun nnmairix-group-change-query-this-group (&optional query)
895 "Set QUERY for group under cursor."
897 (let* ((group (gnus-group-group-name))
898 (method (gnus-find-method-for-group group))
899 (oldquery (gnus-group-get-parameter group 'query t)))
900 (if (eq (car method) 'nnmairix)
902 (when (listp oldquery)
903 (setq oldquery (mapconcat 'identity oldquery " ")))
904 (setq query (or query
905 (read-string "New query: " oldquery)))
906 (when (stringp query)
907 (setq query (split-string query)))
909 (gnus-group-set-parameter group 'query query)
910 (nnmairix-update-and-clear-marks group)))
911 (error "This is no nnmairix group"))))
914 (defun nnmairix-group-toggle-threads-this-group (&optional threads)
915 "Toggle threads parameter for this group.
916 If THREADS is a positive number, set threads parameter to t.
917 If THREADS is a negative number, set it to nil."
919 (let ((group (gnus-group-group-name)))
920 (when (nnmairix-group-toggle-parameter
921 group 'threads "Threads" threads)
922 (nnmairix-update-and-clear-marks group))))
924 (defun nnmairix-group-toggle-propmarks-this-group (&optional propmarks)
925 "Toggle marks propagation for this group.
926 If PROPMARKS is a positive number, set parameter to t.
927 If PROPMARKS is a negative number, set it to nil."
929 (unless (nnmairix-check-mairix-version "maildirpatch")
930 (error "You need a mairix binary with maildir patch to use this feature. See docs for details"))
931 (let ((group (gnus-group-group-name)))
932 (when (or (not (string= (gnus-group-short-name group)
933 (cadr (assoc 'nnmairix-default-group
934 (gnus-find-method-for-group group)))))
935 (y-or-n-p "You should not activate marks propagation for the default \
936 search group. Are you sure? "))
937 (nnmairix-group-toggle-parameter
938 group 'propmarks "Marks propagation" propmarks))))
940 (defun nnmairix-group-toggle-allowfast-this-group (&optional allowfast)
941 "Toggle fast entering for this group.
942 If ALLOWFAST is a positive number, set parameter to t.
943 If ALLOWFAST is a negative number, set it to nil."
945 (nnmairix-group-toggle-parameter
946 (gnus-group-group-name) 'allow-fast "Fast entering" allowfast))
949 (defun nnmairix-group-toggle-readmarks-this-group (&optional readmarks)
950 "Toggle read/unread marks for this group.
951 If READMARKS is a positive number, articles will always be read.
952 If READMARKS is a negative number, articles will always be unread.
953 If READMARKS is t or zero, marks will stay unchanged."
955 (let* ((group (gnus-group-group-name))
956 (method (gnus-find-method-for-group group))
957 (readmarks (or readmarks
958 (gnus-group-get-parameter group 'readmarks))))
959 (if (eq (car method) 'nnmairix)
961 ((or (and (numberp readmarks) (< readmarks 0))
962 (eq readmarks 'read))
963 (gnus-group-set-parameter group 'readmarks 'unread)
964 (nnheader-message 3 "Articles in %s always unread." group))
965 ((or (and (numberp readmarks) (> readmarks 0))
967 (gnus-group-set-parameter group 'readmarks 'read)
968 (nnheader-message 3 "Articles in %s always read." group))
970 (gnus-group-set-parameter group 'readmarks nil)
971 (nnheader-message 3 "Read marks in %s stay unchanged." group)))
972 (error "This is no nnmairix group"))))
975 (defun nnmairix-search (query &optional server threads)
976 "Sends QUERY to nnmairix backend SERVER, using default its search group.
978 Default search group is automatically entered and results are shown.
979 If THREADS is t, enable threads.
980 If THREADS is a negative number, disable threads.
981 Otherwise, leave threads parameter as it is."
982 (interactive (list (read-string "Query: ")))
984 (setq server (car (nnmairix-get-server))))
986 (error "No opened nnmairix server found")
987 (setq server (gnus-server-to-method server)))
988 (nnmairix-open-server (nth 1 server))
989 (let* ((qualgroup (gnus-group-prefixed-name nnmairix-default-group
990 (list 'nnmairix (nth 1 server)))))
991 (set-buffer gnus-group-buffer)
992 (when (stringp query)
993 (setq query (split-string query)))
994 (gnus-group-set-parameter qualgroup 'query query)
995 (if (symbolp threads)
996 (when (eq threads 't)
997 (gnus-group-set-parameter qualgroup 'threads t))
999 (gnus-group-set-parameter qualgroup 'threads nil)))
1000 (nnmairix-update-and-clear-marks qualgroup)
1001 (unless (equal (gnus-active qualgroup) '(1 . 0))
1002 (gnus-group-read-group nil t qualgroup))))
1004 (defun nnmairix-search-thread-this-article ()
1005 "Search thread for the current article.
1006 This is effectively a shortcut for calling `nnmairix-search'
1007 with m:msgid of the current article and enabled threads."
1010 (nnmairix-backend-to-server gnus-current-select-method))
1013 (if (gnus-buffer-live-p gnus-article-buffer)
1016 (set-buffer gnus-article-buffer)
1017 (gnus-summary-toggle-header 1)
1018 (setq mid (message-fetch-field "Message-ID")))
1019 (while (string-match "[<>]" mid)
1020 (setq mid (replace-match "" t t mid)))
1021 (nnmairix-search (concat "m:" mid) server t))
1022 (message "No article buffer."))
1023 (error "No nnmairix server found for back end %s:%s"
1024 (symbol-name (car gnus-current-select-method))
1025 (nth 1 gnus-current-select-method)))))
1027 (defun nnmairix-search-from-this-article ()
1028 "Search messages from sender of the current article.
1029 This is effectively a shortcut for calling `nnmairix-search' with
1033 (nnmairix-backend-to-server gnus-current-select-method))
1036 (if (gnus-buffer-live-p gnus-article-buffer)
1039 (set-buffer gnus-article-buffer)
1040 (gnus-summary-toggle-header 1)
1041 (setq from (cadr (gnus-extract-address-components
1042 (gnus-fetch-field "From"))))
1043 (nnmairix-search (concat "f:" from) server -1)))
1044 (message "No article buffer."))
1045 (error "No nnmairix server found for back end %s:%s"
1046 (symbol-name (car gnus-current-select-method))
1047 (nth 1 gnus-current-select-method)))))
1050 (defun nnmairix-purge-old-groups (&optional dontask server)
1051 "Delete mairix search groups which are no longer used.
1053 You may want to call this from time to time if you are creating
1054 and deleting lots of nnmairix groups. If DONTASK is t, do not ask
1055 before deleting a group on the back end. SERVER specifies nnmairix server."
1057 (let ((server (or server
1058 (gnus-server-to-method (car (nnmairix-get-server))))))
1059 (if (nnmairix-open-server (nth 1 server))
1060 (when (nnmairix-call-backend
1061 "request-list" nnmairix-backend-server)
1062 (let (cur qualgroup folder)
1064 (set-buffer nntp-server-buffer)
1065 (goto-char (point-min))
1066 (while (re-search-forward nnmairix-group-regexp (point-max) t)
1067 (setq cur (match-string 0)
1068 qualgroup (gnus-group-prefixed-name
1069 (match-string 1) server))
1070 (when (not (and (gnus-group-entry qualgroup)
1072 (gnus-group-get-parameter
1073 qualgroup 'folder))))
1076 (concat "Delete group " cur
1077 " on server " nnmairix-backend-server "? ")))
1078 (nnmairix-call-backend
1079 "request-delete-group" cur t nnmairix-backend-server)))))))
1080 (message "Couldn't open server %s" (nth 1 server)))))
1083 (defun nnmairix-update-database (&optional servers)
1084 "Call mairix for updating the database for SERVERS.
1086 If SERVERS is nil, do update for all nnmairix servers. Mairix
1087 will be called asynchronously unless
1088 `nnmairix-mairix-synchronous-update' is t. Mairix will be called
1089 with `nnmairix-mairix-update-options'."
1091 (let ((servers (or servers
1092 (nnmairix-get-nnmairix-servers)))
1093 args cur commandsplit)
1095 (setq cur (car (pop servers)))
1096 (nnmairix-open-server
1097 (nth 1 (gnus-server-to-method cur)))
1098 (setq commandsplit (split-string nnmairix-mairix-command))
1099 (nnheader-message 7 "Updating mairix database for %s..." cur)
1100 (if nnmairix-mairix-synchronous-update
1102 (setq args (append (list (car commandsplit) nil
1103 (get-buffer nnmairix-mairix-output-buffer)
1105 (if (> (length commandsplit) 1)
1106 (setq args (append args (cdr commandsplit) nnmairix-mairix-update-options))
1107 (setq args (append args nnmairix-mairix-update-options)))
1108 (apply 'call-process args)
1109 (nnheader-message 7 "Updating mairix database for %s... done" cur))
1111 (setq args (append (list cur (get-buffer nnmairix-mairix-output-buffer)
1112 (car commandsplit))))
1113 (if (> (length commandsplit) 1)
1114 (setq args (append args (cdr commandsplit) nnmairix-mairix-update-options))
1115 (setq args (append args nnmairix-mairix-update-options)))
1116 (set-process-sentinel (apply 'start-process args)
1117 'nnmairix-sentinel-mairix-update-finished))))))
1119 ;; Silence byte-compiler.
1120 (defvar gnus-registry-install)
1121 (autoload 'gnus-registry-fetch-group "gnus-registry")
1123 (defun nnmairix-group-delete-recreate-this-group ()
1124 "Deletes and recreates group on the back end.
1125 You can use this function on nnmairix groups which continously
1126 show wrong article counts."
1128 (let* ((group (gnus-group-group-name))
1129 (method (gnus-find-method-for-group group)))
1130 (unless (eq (car method) 'nnmairix)
1131 (error "This is not a nnmairix group"))
1133 (format "Really recreate group %s on the back end? " group))
1134 (nnmairix-delete-recreate-group group)
1135 (gnus-group-get-new-news-this-group))))
1137 (defun nnmairix-propagate-marks (&optional server)
1138 "Propagate marks from nnmairix group to original articles.
1139 Unless SERVER is explicitly specified, will use the last opened
1140 nnmairix server. Only marks from current session will be set."
1143 (nnmairix-open-server server)
1144 (unless (eq (car gnus-current-select-method) 'nnmairix)
1145 (if nnmairix-current-server
1146 (nnmairix-open-server nnmairix-current-server)
1147 (error "No opened nnmairix server"))))
1148 (if nnmairix-marks-cache
1149 (let (number ogroup number-cache method mid-marks temp)
1150 ;; first we get the article numbers
1152 (while (setq ogroup (pop nnmairix-marks-cache))
1153 (while (setq mid-marks (pop (cdr ogroup)))
1156 (gnus-request-head (car mid-marks) (car ogroup))))
1159 3 "Unable to set mark: couldn't determine article number for %s in %s"
1160 (car mid-marks) (car ogroup))
1161 (throw 'problem nil))
1162 (setq temp (assoc (car ogroup) number-cache))
1165 (dolist (cur (cdr temp))
1166 (when (equal (cdr cur) (list (nth 1 mid-marks) (nth 2 mid-marks)))
1167 (nconc (car cur) (list number))
1169 (nconc temp (list (list (list number) (nth 1 mid-marks) (nth 2 mid-marks)))))
1170 (push (list (car ogroup) (list (list number) (nth 1 mid-marks) (nth 2 mid-marks)))
1172 ;; now we set the marks
1174 (set-buffer gnus-group-buffer)
1175 (nnheader-message 5 "nnmairix: Propagating marks...")
1176 (dolist (cur number-cache)
1177 (setq method (gnus-find-method-for-group (car cur)))
1178 (apply (intern (format "%s-%s"
1179 (symbol-name (car method))
1180 "request-set-mark"))
1181 (gnus-group-short-name (car cur))
1183 (list (nth 1 method)))
1184 (gnus-group-jump-to-group (car cur))
1185 (gnus-group-get-new-news-this-group)))
1186 (nnheader-message 5 "nnmairix: Propagating marks... done"))
1187 (nnheader-message 3 "No marks to propagate.")))
1189 (defun nnmairix-update-groups (servername &optional skipdefault updatedb)
1190 "Update all search groups on SERVERNAME.
1191 If SKIPDEFAULT is t, the default search group will not be
1193 If UPDATEDB is t, database for SERVERNAME will be updated first."
1194 (interactive (list (completing-read "Update groups on server: "
1195 (nnmairix-get-nnmairix-servers))))
1197 (when (string-match ".*:\\(.*\\)" servername)
1198 (setq servername (match-string 1 servername)))
1199 (if (not (assoc (format "nnmairix:%s" servername)
1200 (nnmairix-get-nnmairix-servers)))
1201 (nnheader-message 3 "Server %s not opened" servername)
1203 (let ((nnmairix-mairix-synchronous-update t))
1204 (nnmairix-update-database
1205 (list (list (format "nnmairix:%s" servername))))))
1206 (let ((groups (nnmairix-get-groups-from-server servername))
1210 (format "nnmairix+%s:%s"
1213 (assoc 'nnmairix-default-group
1214 (gnus-server-to-method
1215 (format "nnmairix:%s" servername)))))))
1216 (dolist (cur groups)
1217 (unless (and skipdefault
1218 (string= (car cur) default))
1219 (gnus-group-jump-to-group (car cur))
1220 (gnus-group-get-new-news-this-group)))))))
1222 (defun nnmairix-remove-tick-mark-original-article ()
1223 "Remove tick mark from original article.
1224 Marks propagation has to be enabled for this to work."
1226 (unless (eq (car gnus-current-select-method) 'nnmairix)
1227 (error "Not in a nnmairix group"))
1229 (let ((mid (mail-header-message-id (gnus-summary-article-header)))
1232 (setq groups (nnmairix-determine-original-group-from-registry mid))
1234 nnmairix-only-use-registry)
1236 (nnmairix-determine-original-group-from-path mid nnmairix-current-server)))
1238 (error "Couldn't find original article"))
1239 (dolist (cur groups)
1240 (push `(,cur (,mid del (tick))) nnmairix-marks-cache))
1241 (nnheader-message 5 "Will remove tick mark for %s upon closing." mid)))))
1243 ;;; ==== Helper functions
1245 (defun nnmairix-request-group-with-article-number-correction (folder qualgroup)
1246 "Request FOLDER on back end for nnmairix QUALGROUP and article number correction."
1248 (nnmairix-call-backend "request-group" folder nnmairix-backend-server)
1249 (set-buffer nnmairix-mairix-output-buffer)
1250 (goto-char (point-min))
1251 (re-search-forward "^Matched.*messages")
1252 (nnheader-message 7 (match-string 0))
1253 (set-buffer nntp-server-buffer)
1254 (goto-char (point-min))
1255 (let ((status (read (current-buffer)))
1256 (total (read (current-buffer)))
1257 (low (read (current-buffer)))
1258 (high (read (current-buffer)))
1259 (corr (gnus-group-get-parameter qualgroup 'numcorr t)))
1262 ;; Article number correction
1264 (> (+ (car (cddr corr)) high) 0))
1266 (when (car corr) ;Group has changed
1270 (+ (car (cddr corr)) high)))
1271 (gnus-group-set-parameter
1272 qualgroup 'numcorr corr))
1273 (setq low (+ low (cadr corr))
1274 high (+ high (cadr corr))))
1275 (when (member nnmairix-backend
1276 nnmairix-delete-and-create-on-change)
1277 (gnus-group-set-parameter
1278 qualgroup 'numcorr (list nil 0 high))))
1280 (insert (format "%d %d %d %d %s" status total low high
1281 (gnus-group-real-name qualgroup)))
1285 'nnmairix "Error calling back end on group %s" folder)
1288 (defun nnmairix-call-mairix-binary (command folder searchquery threads)
1289 "Call mairix binary with COMMAND, using FOLDER and SEARCHQUERY.
1290 If THREADS is non-nil, enable full threads."
1291 (let ((args (cons (car command) '(nil t nil))))
1294 (get-buffer-create nnmairix-mairix-output-buffer))
1296 (when (> (length command) 1)
1297 (setq args (append args (cdr command))))
1298 (when nnmairix-mairix-search-options
1299 (setq args (append args nnmairix-mairix-search-options)))
1300 ;; If we have a patched mairix binary, call it with "-c"
1301 (when (nnmairix-check-mairix-version "maildirpatch")
1302 (setq args (append args '("-c"))))
1304 (setq args (append args '("-t"))))
1305 (apply 'call-process
1306 (append args (list "-o" folder) searchquery)))))
1308 (defun nnmairix-call-mairix-binary-raw (command query)
1309 "Call mairix binary with COMMAND and QUERY in raw mode."
1310 (let ((args (cons (car command) '(nil t nil))))
1313 (get-buffer-create nnmairix-mairix-output-buffer))
1315 (when (> (length command) 1)
1316 (setq args (append args (cdr command))))
1317 (setq args (append args '("-r")))
1318 (apply 'call-process
1319 (append args query)))))
1321 (defun nnmairix-get-server ()
1322 "If there exists just one nnmairix server, return its value.
1323 Otherwise, ask user for server."
1324 (let ((openedserver (nnmairix-get-nnmairix-servers)))
1325 (when (not openedserver)
1326 (error "No opened nnmairix server found"))
1327 (if (> (length openedserver) 1)
1331 (setq nnmairix-last-server
1332 (list (completing-read "Server: " openedserver nil 1
1333 (or nnmairix-last-server
1335 nnmairix-last-server)
1336 (car openedserver))))
1338 (defun nnmairix-get-nnmairix-servers (&optional all)
1339 "Return available nnmairix servers.
1340 If ALL is t, return also the unopened/failed ones."
1341 (let ((alist gnus-opened-servers)
1342 server openedserver)
1344 (setq server (pop alist))
1347 (eq (cadr server) 'ok))
1348 (eq (caar server) 'nnmairix)
1349 (not (member (car server) gnus-ephemeral-servers)))
1351 (concat (symbol-name (caar server)) ":" (nth 1 (car server))))
1352 (push (list server) openedserver)))
1355 (defun nnmairix-get-valid-servers ()
1356 "Return list of valid back end servers for nnmairix groups."
1357 (let ((alist gnus-opened-servers)
1358 (mairixservers (nnmairix-get-nnmairix-servers t))
1359 server mserver openedserver occ cur)
1360 ;; Get list of all nnmairix backends (i.e. backends which are
1361 ;; already occupied)
1362 (dolist (cur mairixservers)
1366 (cadr (assoc 'nnmairix-backend
1367 (gnus-server-to-method (car cur)))))
1369 (cadr (assoc 'nnmairix-backend-server
1370 (gnus-server-to-method (car cur)))))
1373 (setq server (pop alist))
1374 (setq mserver (gnus-method-to-server (car server)))
1375 ;; If this is the native server, convert it to the real server
1376 ;; name to avoid confusion
1377 (when (string= mserver "native")
1378 (setq mserver (format "%s:%s"
1380 (nth 1 (car server)))))
1382 (eq (cadr server) 'ok)
1383 (member (caar server) nnmairix-valid-backends)
1384 (not (member (car server) gnus-ephemeral-servers))
1385 (not (member (gnus-method-to-server (car server)) occ)))
1391 (defun nnmairix-get-groups-from-server (servername)
1392 "Return all groups for nnmairix server SERVERNAME."
1393 (let ((searchstring (format "nnmairix\\+%s:" servername))
1395 (dolist (cur gnus-newsrc-alist)
1396 (when (string-match searchstring
1398 (push (list (car cur)) groups)))
1401 (defun nnmairix-call-backend (func &rest args)
1402 "Call a function FUNC on backend with ARGS."
1403 (apply (intern (format "%s-%s" (symbol-name nnmairix-backend) func)) args))
1405 (defun nnmairix-get-backend-folder (group &optional server)
1406 "Return back end GROUP from nnmairix group on SERVER."
1407 (let* ((qualgroup (if server
1408 (gnus-group-prefixed-name group (list 'nnmairix server))
1410 (folder (gnus-group-get-parameter qualgroup 'folder)))
1413 (defun nnmairix-get-numcorr (group &optional server)
1414 "Return values for article number correction nnmairix GROUP on SERVER."
1415 (let* ((qualgroup (if server
1416 (gnus-group-prefixed-name group (list 'nnmairix server))
1418 (corr (gnus-group-get-parameter qualgroup 'numcorr t)))
1422 (defun nnmairix-rename-files-consecutively (path)
1423 "Rename all nnml mail files in PATH so that they have consecutive numbers.
1424 This should correct problems of wrong article counts when using
1425 nnmairix with nnml backends."
1428 (mapcar 'string-to-number
1429 (directory-files path nil "[0-9]+" t))
1431 (lastplusone (car files))
1432 (path (file-name-as-directory path)))
1434 (when (not (= cur lastplusone))
1435 (rename-file (concat path
1436 (number-to-string cur))
1438 (number-to-string lastplusone)))
1439 (setq cur lastplusone))
1440 (setq lastplusone (1+ cur)))))
1442 (defun nnmairix-replace-group-and-numbers (articles backendgroup mairixgroup numc)
1443 "Replace folder names in Xref header and correct article numbers.
1444 Do this for all ARTICLES on BACKENDGROUP. Replace using
1445 MAIRIXGROUP. NUMC contains values for article number correction."
1446 (let ((buf (get-buffer-create " *nnmairix buffer*"))
1447 (corr (not (zerop numc)))
1448 (name (buffer-name nntp-server-buffer))
1453 (set-buffer nntp-server-buffer)
1454 (goto-char (point-min))
1455 (nnheader-message 7 "nnmairix: Rewriting headers...")
1458 (when (or (looking-at (number-to-string article))
1459 (nnheader-find-nov-line article))
1460 (setq cur (nnheader-parse-nov))
1462 (setq article (+ (mail-header-number cur) numc))
1463 (mail-header-set-number cur article))
1464 (setq xref (mail-header-xref cur))
1465 (when (and (stringp xref)
1466 (string-match (format "[ \t]%s:[0-9]+" backendgroup) xref))
1467 (setq xref (replace-match (format " %s:%d" mairixgroup article) t nil xref))
1468 (mail-header-set-xref cur xref))
1470 (nnheader-insert-nov cur)
1471 (set-buffer nntp-server-buffer)
1475 (nnheader-message 7 "nnmairix: Rewriting headers... done")
1476 (kill-buffer nntp-server-buffer)
1478 (rename-buffer name)
1479 (setq nntp-server-buffer buf))))
1481 (defun nnmairix-backend-to-server (server)
1482 "Return nnmairix server most probably responsible for back end SERVER.
1483 User will be asked if this cannot be determined. Result is saved in
1484 parameter 'indexed-servers of corresponding default search
1486 (let ((allservers (nnmairix-get-nnmairix-servers))
1487 mairixserver found defaultgroup)
1488 (if (> (length allservers) 1)
1490 ;; If there is more than one nnmairix server, we go through them
1491 (while (and allservers (not found))
1492 (setq mairixserver (gnus-server-to-method (car (pop allservers))))
1493 ;; First we look if SERVER is the backend of current nnmairix server
1494 (setq found (and (eq (cadr (assoc 'nnmairix-backend mairixserver))
1496 (string= (cadr (assoc 'nnmairix-backend-server mairixserver))
1498 ;; If that's not the case, we look at 'indexed-servers
1499 ;; variable in default search group
1501 (setq defaultgroup (cadr (assoc 'nnmairix-default-group mairixserver)))
1502 (setq found (member (gnus-method-to-server server)
1503 (gnus-group-get-parameter
1504 (gnus-group-prefixed-name defaultgroup
1506 'indexed-servers t)))))
1507 ;; If still not found, we ask user
1510 (gnus-server-to-method
1512 (format "Cannot determine which nnmairix server indexes %s. Please specify: "
1513 (gnus-method-to-server server))
1514 (nnmairix-get-nnmairix-servers) nil nil "nnmairix:")))
1515 ;; Save result in parameter of default search group so that
1516 ;; we don't have to ask again
1517 (setq defaultgroup (gnus-group-prefixed-name
1518 (cadr (assoc 'nnmairix-default-group mairixserver)) mairixserver))
1519 (gnus-group-set-parameter
1522 (append (gnus-group-get-parameter defaultgroup 'indexed-servers t)
1523 (list (gnus-method-to-server server)))))
1525 ;; If there is just one (or none) nnmairix server:
1526 (gnus-server-to-method (caar allservers)))))
1529 (defun nnmairix-delete-recreate-group (group)
1530 "Delete and recreate folder from GROUP on the back end."
1531 (when (member nnmairix-backend nnmairix-delete-and-create-on-change)
1532 (let ((folder (gnus-group-get-parameter group 'folder)))
1533 (if (string-match nnmairix-group-regexp folder)
1535 (nnmairix-call-backend "open-server"
1536 nnmairix-backend-server)
1537 (nnmairix-call-backend "request-delete-group"
1538 folder t nnmairix-backend-server)
1539 (nnmairix-call-backend "request-create-group"
1540 folder nnmairix-backend-server))
1541 (error "`nnmairix-delete-recreate-group' called on \
1542 non-mairix group. Check folder parameter")))))
1544 (defun nnmairix-update-and-clear-marks (group &optional method)
1545 "Update group and clear all marks from GROUP using METHOD."
1546 (let ((method (or method
1547 (gnus-find-method-for-group group)))
1548 (corr (gnus-group-get-parameter group 'numcorr t))
1550 (unless (or (gnus-group-prefixed-p group)
1552 (setq group (gnus-group-prefixed-name group method)))
1553 (if (eq (nth 0 method) 'nnmairix)
1555 (nnmairix-open-server (nth 1 method))
1556 (set-buffer gnus-group-buffer)
1557 ;; (gnus-group-set-parameter group 'propmarks nil)
1558 (setq info (gnus-get-info group))
1559 ;; Clear active and info
1560 (gnus-set-active group nil)
1561 (gnus-info-clear-data info)
1562 ;; Delete and re-create group if needed
1563 (nnmairix-delete-recreate-group group)
1564 ;; set flag that group has changed for article number correction
1565 (when (member nnmairix-backend nnmairix-delete-and-create-on-change)
1568 (gnus-group-set-parameter group 'numcorr corr)))
1569 (gnus-group-jump-to-group group)
1570 (gnus-group-get-new-news-this-group))
1571 (error "`nnmairix-update-and-clear-marks' called with non-nnmairix group"))))
1573 (defun nnmairix-sentinel-mairix-update-finished (proc status)
1574 "Sentinel for mairix update process PROC with STATUS."
1575 (if (equal status "finished\n")
1576 (nnheader-message 7 "Updating mairix database for %s... done" proc)
1577 (error "There was an error updating the mairix database for server %s. \
1578 See %s for details" proc nnmairix-mairix-output-buffer)))
1580 (defun nnmairix-create-message-line-for-search ()
1581 "Create message line for interactive query in minibuffer."
1585 (format "%c=%s" (car cur) (nth 3 cur))))
1586 nnmairix-interactive-query-parameters ","))
1588 (defun nnmairix-replace-illegal-chars (header)
1589 "Replace illegal characters in HEADER for mairix query."
1591 (if (> emacs-major-version 20)
1592 (while (string-match "[^-.@/,& [:alnum:]]" header)
1593 (setq header (replace-match "" t t header)))
1594 (while (string-match "[[]{}:<>]" header)
1595 (setq header (replace-match "" t t header))))
1596 (while (string-match "[-& ]" header)
1597 (setq header (replace-match "," t t header)))
1600 (defun nnmairix-group-toggle-parameter (group parameter description &optional par)
1601 "Toggle on GROUP a certain PARAMETER.
1602 DESCRIPTION will be shown to the user with the activation
1603 status. If PAR is a positive number, the group parameter will be
1604 set to t and to nil otherwise."
1605 (let* ((method (gnus-find-method-for-group group))
1607 (not (gnus-group-get-parameter group parameter)))))
1608 (if (eq (car method) 'nnmairix)
1611 (setq par (> par 0)))
1612 (gnus-group-set-parameter group parameter par)
1614 (message "%s activated for group %s" description group)
1615 (message "%s deactivated for group %s" description group))
1617 (error "This is no nnmairix group")
1620 ;; Search for original article helper functions
1622 (defun nnmairix-goto-original-article (&optional no-registry)
1623 "Jump to the original group and display article.
1624 The original group of the article is first determined with the
1625 registry (if enabled). If the registry is not enabled or did not
1626 find the article or the prefix NO-REGISTRY is non-nil, this
1627 function will try to determine the original group form the path
1628 of the mail file. The path is obtained through another mairix
1629 search in raw mode."
1631 (when (not (eq (car gnus-current-select-method) 'nnmairix))
1632 (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
1633 (if (eq (car method) 'nnmairix)
1634 (nnmairix-open-server (nth 1 method))
1635 (error "Not in a nnmairix group"))))
1636 (when (not (gnus-buffer-live-p gnus-article-buffer))
1637 (error "No article buffer available"))
1638 (let ((server (nth 1 gnus-current-select-method))
1639 mid rval group allgroups)
1642 (set-buffer gnus-article-buffer)
1643 (gnus-summary-toggle-header 1)
1644 (setq mid (message-fetch-field "Message-ID"))
1645 ;; first check the registry (if available)
1647 (setq allgroups (nnmairix-determine-original-group-from-registry mid)))
1648 (unless (or allgroups
1649 nnmairix-only-use-registry)
1650 ;; registry was not available or did not find article
1651 ;; so we search again with mairix in raw mode to get filename
1653 (nnmairix-determine-original-group-from-path mid server))
1654 ;; if available and allowed, add this entry to the registry
1655 (when (and (not no-registry)
1656 (boundp 'gnus-registry-install)
1657 gnus-registry-install)
1658 (dolist (cur allgroups)
1659 (unless (gnus-parameter-registry-ignore cur)
1660 (gnus-registry-add-group mid cur)))))
1661 (if (> (length allgroups) 1)
1664 "Message exists in more than one group. Choose: "
1666 (setq group (car allgroups))))
1668 ;; show article in summary buffer
1669 (nnmairix-show-original-article group mid)
1670 (nnheader-message 3 "Couldn't find original article"))))
1672 (defun nnmairix-determine-original-group-from-registry (mid)
1673 "Try to determinale original group for message-id MID from the registry."
1674 (when (and (boundp 'gnus-registry-install)
1675 gnus-registry-install)
1676 (unless (string-match "^<" mid)
1677 (set mid (concat "<" mid)))
1678 (unless (string-match ">$" mid)
1679 (set mid (concat mid ">")))
1680 (gnus-registry-fetch-groups mid)))
1682 (defun nnmairix-determine-original-group-from-path (mid server)
1683 "Determine original group(s) for message-id MID from the file path.
1684 The file path is obtained through a mairix search for the id on
1686 (nnmairix-open-server server)
1687 (while (string-match "[<>]" mid)
1688 (setq mid (replace-match "" t t mid)))
1690 (if (zerop (nnmairix-call-mairix-binary-raw
1691 (split-string nnmairix-mairix-command)
1692 (list (concat "m:" mid))))
1694 (set-buffer nnmairix-mairix-output-buffer)
1695 (goto-char (point-min))
1696 (while (re-search-forward "^/.*$" nil t)
1697 (push (nnmairix-get-group-from-file-path (match-string 0))
1700 (error "Mairix could not find original article. See buffer %s for details"
1701 nnmairix-mairix-output-buffer))
1704 (defun nnmairix-get-group-from-file-path (file)
1705 "Get group by parsing the message location FILE."
1706 (let (path filename serverbase group maildirflag allgroups)
1707 (string-match "^\\(.*\\)/\\(.*?\\)$" file)
1708 (setq path (expand-file-name (match-string 1 file)))
1709 (setq filename (match-string 2 file))
1710 ;; when we deal with maildir, remove cur/new/tmp from path
1711 (setq maildirflag (string-match ".+\\..+\\..+" filename))
1714 (replace-regexp-in-string
1715 ".*\\(/cur\\|/new\\|/tmp\\)$" "" path t t 1)))
1716 ;; we first check nnml and nnmaildir servers
1720 (dolist (cur gnus-opened-servers)
1721 (when (or (and (not maildirflag)
1722 (eq (caar cur) 'nnml))
1724 (eq (caar cur) 'nnmaildir)))
1725 ;; get base path from server
1727 (setq serverbase (cadr (assoc 'directory (car cur))))
1728 (setq serverbase (cadr (assoc 'nnml-directory (car cur))))
1730 (setq serverbase nnml-directory)))
1731 (setq serverbase (file-name-as-directory
1732 (expand-file-name serverbase)))
1733 (when (string-match (concat serverbase "\\(.*\\)") path)
1734 ;; looks good - rest of the path should be the group
1735 (setq group (match-string 1 path))
1736 (when (string-match "/$" group)
1737 (setq group (replace-match "" t t group)))
1739 ;; for nnml: convert slashes to dots
1740 (while (string-match "/" group)
1741 (setq group (replace-match "." t t group))))
1742 (setq group (gnus-group-prefixed-name group (car cur)))
1743 ;; check whether this group actually exists
1744 (when (gnus-group-entry group)
1745 (throw 'found group)))))))
1747 ;; we haven't found it yet --> look for nnimap groups. Assume
1748 ;; last element of the path is the group. This might fail since
1749 ;; IMAP servers may present groups to the client in arbitrary
1751 (string-match "^.*/\\.?\\(.*\\)$" path)
1752 (setq group (match-string 1 path))
1753 ;; convert dots to slashes (nested group)
1754 (while (string-match "\\." group)
1755 (setq group (replace-match "/" t t group)))
1756 (dolist (cur gnus-opened-servers)
1757 (when (eq (caar cur) 'nnimap)
1758 (when (gnus-group-entry
1759 (gnus-group-prefixed-name group (car cur)))
1761 (gnus-group-prefixed-name group (car cur))
1763 (if (> (length allgroups) 1)
1764 (setq group (completing-read
1765 "Group %s exists on more than one IMAP server. Choose: "
1767 (setq group (car allgroups))))
1770 (defun nnmairix-show-original-article (group mid)
1771 "Switch to GROUP and display Article with message-id MID."
1772 (unless (string-match "^<" mid)
1773 (set mid (concat "<" mid)))
1774 (unless (string-match ">$" mid)
1775 (set mid (concat mid ">")))
1776 (when (string-match "Summary" (buffer-name (current-buffer)))
1777 (gnus-summary-exit))
1778 (pop-to-buffer gnus-group-buffer)
1779 (gnus-group-jump-to-group group)
1780 (gnus-summary-read-group group 1 t)
1781 (gnus-summary-refer-article mid)
1782 (gnus-summary-limit-to-headers (format "message-id: %s" mid))
1783 (gnus-summary-select-article)
1785 (gnus-summary-show-article)
1786 (nnheader-message 5 "Switched to group %s." group))
1788 (defun nnmairix-map-range (func range)
1789 "Map function FUNC on all members of RANGE."
1792 (funcall func range))
1794 (mapcar (lambda (cur)
1798 (funcall func (car cur))
1799 (funcall func (cdr cur))))
1801 (funcall func cur))))
1804 (defun nnmairix-check-mairix-version (version &optional server)
1805 "Check mairix VERSION on SERVER.
1806 If VERSION is a number: specifies the minimum version.
1807 If VERSION is a string: must be contained in mairix version output."
1809 (setq server nnmairix-current-server))
1810 (let ((versionstring (cadr (assoc server nnmairix-version-output))))
1811 (unless versionstring
1812 ;; call "mairix -V" to get the version string
1815 (let* ((commandsplit (split-string nnmairix-mairix-command))
1816 (args (append (list (car commandsplit))
1817 `(nil t nil) (cdr commandsplit) '("-V"))))
1818 (apply 'call-process args)
1819 (goto-char (point-min))
1820 (re-search-forward "mairix.*")
1822 ;; save version string for current session
1823 (setq nnmairix-version-output
1824 (append nnmairix-version-output
1825 (list (list server versionstring)))))
1828 (string-match version versionstring))
1830 (<= version (string-to-number
1832 (string-match "mairix \\([0-9\\.]+\\)" versionstring)
1833 (match-string 1 versionstring))))))))
1835 ;; ==== Widget stuff
1837 (defvar nnmairix-widgets)
1838 (defvar nnmairix-widgets-values nil)
1840 (defun nnmairix-widget-search-from-this-article ()
1841 "Create mairix query based on current article using graphical widgets."
1843 (nnmairix-widget-search
1844 (nnmairix-widget-get-values)))
1846 (defun nnmairix-widget-get-values ()
1847 "Create values for editable fields from current article."
1848 (if (not (gnus-buffer-live-p gnus-article-buffer))
1849 (error "No article buffer available")
1851 (gnus-summary-toggle-header 1)
1852 (set-buffer gnus-article-buffer)
1856 (list (car (cddr field))
1858 (nnmairix-replace-illegal-chars
1859 (gnus-fetch-field (car field)))
1861 nnmairix-widget-fields-list))))
1864 (defun nnmairix-widget-search (&optional mvalues)
1865 "Create mairix query interactively using graphical widgets.
1866 MVALUES may contain values from current article."
1868 ;; Select window for mairix customization
1869 (funcall nnmairix-widget-select-window-function)
1871 (nnmairix-widget-create-query mvalues)
1873 (widget-create 'push-button
1876 (lambda (&rest ignore)
1877 (nnmairix-widget-send-query nnmairix-widgets
1879 (lambda (&rest ignore)
1880 (nnmairix-widget-send-query nnmairix-widgets
1884 (widget-create 'push-button
1887 (lambda (&rest ignore)
1888 (nnmairix-widget-create-group nnmairix-widgets
1890 (lambda (&rest ignore)
1891 (nnmairix-widget-create-group nnmairix-widgets
1893 "Create permanent group")
1895 (widget-create 'push-button
1896 :notify (lambda (&rest ignore)
1897 (kill-buffer nnmairix-customize-query-buffer))
1899 (use-local-map widget-keymap)
1901 (goto-char (point-min)))
1903 (defun nnmairix-widget-send-query (widgets &optional withvalues)
1904 "Send query from WIDGETS to mairix binary.
1905 If WITHVALUES is t, query is based on current article."
1907 (nnmairix-widget-make-query-from-widgets widgets)
1909 (gnus-method-to-server
1910 (nnmairix-backend-to-server gnus-current-select-method))
1911 (car (nnmairix-get-server)))
1912 (if (widget-value (cadr (assoc "Threads" widgets)))
1915 (kill-buffer nnmairix-customize-query-buffer))
1917 (defun nnmairix-widget-create-group (widgets &optional withvalues)
1918 "Create nnmairix group based on current widget values WIDGETS.
1919 If WITHVALUES is t, query is based on current article."
1920 (let ((group (read-string "Name of the group: ")))
1921 (when (not (zerop (length group)))
1922 (nnmairix-create-search-group
1924 (gnus-method-to-server
1925 (nnmairix-backend-to-server gnus-current-select-method))
1926 (car (nnmairix-get-server)))
1928 (nnmairix-widget-make-query-from-widgets widgets)
1929 (widget-value (cadr (assoc "Threads" widgets))))))
1930 (kill-buffer nnmairix-customize-query-buffer))
1933 (defun nnmairix-widget-make-query-from-widgets (widgets)
1934 "Create mairix query from widget values WIDGETS."
1935 (let (query temp flag)
1936 ;; first we do the editable fields
1937 (dolist (cur nnmairix-widget-fields-list)
1938 ;; See if checkbox is checked
1940 (cadr (assoc (concat "c" (car (cddr cur))) widgets)))
1941 ;; create query for the field
1946 (nnmairix-replace-illegal-chars
1948 (cadr (assoc (concat "e" (car (cddr cur))) widgets)))))
1951 (when (member 'flags nnmairix-widget-other)
1957 (widget-value (cadr (assoc (car flag) nnmairix-widgets))))
1958 (if (string= "yes" temp)
1960 (if (string= "no" temp)
1961 (concat "-" (cadr flag))))))
1962 '(("seen" "s") ("replied" "r") ("flagged" "f")) ""))
1963 (when (not (zerop (length flag)))
1964 (push (concat "F:" flag) query)))
1965 ;; return query string
1966 (mapconcat 'identity query " ")))
1969 (defun nnmairix-widget-create-query (&optional values)
1970 "Create widgets for creating mairix queries.
1971 Fill in VALUES if based on an article."
1973 (when (get-buffer nnmairix-customize-query-buffer)
1974 (kill-buffer nnmairix-customize-query-buffer))
1975 (switch-to-buffer nnmairix-customize-query-buffer)
1976 (kill-all-local-variables)
1978 (widget-insert "Specify your query for Mairix (check boxes for activating fields):\n\n")
1979 (widget-insert "(Whitespaces will be converted to ',' (i.e. AND). Use '/' for OR.)\n\n")
1980 ; (make-local-variable 'nnmairix-widgets)
1981 (setq nnmairix-widgets (nnmairix-widget-build-editable-fields values))
1982 (when (member 'flags nnmairix-widget-other)
1983 (widget-insert "\nFlags:\n Seen: ")
1984 (nnmairix-widget-add "seen"
1987 '(item "yes") '(item "no") '(item "ignore"))
1988 (widget-insert " Replied: ")
1989 (nnmairix-widget-add "replied"
1992 '(item "yes") '(item "no") '(item "ignore"))
1993 (widget-insert " Ticked: ")
1994 (nnmairix-widget-add "flagged"
1997 '(item "yes") '(item "no") '(item "ignore")))
1998 (when (member 'threads nnmairix-widget-other)
1999 (widget-insert "\n")
2000 (nnmairix-widget-add "Threads" 'checkbox nil))
2001 (widget-insert " Show full threads\n\n")))
2003 (defun nnmairix-widget-build-editable-fields (values)
2004 "Build editable field widgets in `nnmairix-widget-fields-list'.
2005 VALUES may contain values for editable fields from current article."
2006 ;; how can this be done less ugly?
2011 (setq field (car (cddr field)))
2017 (widget-create 'checkbox
2019 :notify (lambda (widget &rest ignore)
2020 (nnmairix-widget-toggle-activate widget))
2025 (widget-create 'editable-field
2027 :format (concat " " field ":"
2028 (make-string (- 11 (length field)) ?\ )
2030 :value (or (cadr (assoc field values)) ""))))
2032 (widget-insert "\n")
2033 ;; Deactivate editable field
2034 (widget-apply (cadr (nth 1 ret)) :deactivate)))
2035 nnmairix-widget-fields-list)
2038 (defun nnmairix-widget-add (name &rest args)
2039 "Add a widget NAME with optional ARGS."
2042 (apply 'widget-create args))
2045 (defun nnmairix-widget-toggle-activate (widget)
2046 "Toggle activation status of WIDGET depending on corresponding checkbox value."
2047 (let ((field (widget-get widget :tag)))
2048 (if (widget-value widget)
2050 (cadr (assoc (concat "e" field) nnmairix-widgets))
2053 (cadr (assoc (concat "e" field) nnmairix-widgets))
2059 ;; arch-tag: bb187498-b229-4a55-8c07-6d3f80713e94
2060 ;;; nnmairix.el ends here