Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: Lars Clausen <lrclause@cs.uiuc.edu>
Subject: Namazu, BBDB, Gnus
Date: 19 Aug 2002 10:33:58 -0500	[thread overview]
Message-ID: <81wuqmx3q1.fsf@shasta.cs.uiuc.edu> (raw)


I've been looking around for some way to make Gnus, BBDB and a mail DB work
together.  Didn't find any, so I cooked one up with Namazu support.  For
those of you with tens of thousands of old messages, this is a godsend.

Note that this is currently in the 'quick hack' stage.  It assumes use of
nnml and Namazu.  It doesn't require BBDB, but it works better when BBDB is
around.  If somebody wants to integrate something like this in Gnus or
BBDB, that'd be lovely.

-Lars

(defcustom namazu-dir (concat (getenv "HOME") "/Mail/namazu")
  "The dir to search for Namazu database."
  :type 'directory
  :group 'namazu)

(defun string-replace-all (string reg rep)
  "Replace all occurences of reg with rep in string.
Do not pass a reg that matches rep."
  (if (string-match reg string)
      (string-replace-all (replace-match rep t t string) reg rep)
    string)
  )

(defun regexp-matches-to-list (reg subexp)
  "Returns a list of all matches remaining in the buffer"
  (if (re-search-forward reg nil t)
      (cons (match-string subexp) (regexp-matches-to-list reg subexp)))
  )

(defun namazu-select-articles (group regexp)
  "Select articles from group based on Namazu output.
This is a low-level function, you probably want to use
`namazu-search-for-articles' or `namazu-search-by-field'"
  (interactive "sGroup: \nsNamazu regexp: ")
  (let* ((output-buffer (get-buffer-create "*namazu*"))
	 (namazu-return (call-process "namazu" nil (cons output-buffer t) t 
				      "-a" "-l" regexp namazu-dir))
	 (group-name (if (string-match "^nnml\\+Mail:" group)
			 (substring group (match-end 0))
		       (error "Not an nnml group")))
	 (group-dir (string-replace-all group-name "\\." "/"))
	 (dummy (set-buffer output-buffer))
	 (dummy (goto-char 0))
	 (matches (regexp-matches-to-list (concat "/" group-dir "/\\([^/]*\\)$") 1))
	 (dummy (message (concat "group " group-dir " article " (car matches))))
	 (articles (sort (mapcar 'string-to-int matches) '<)))
    (if (not (null articles))
	(gnus-group-read-group t t group articles)
      (message "No articles found"))
    (kill-buffer output-buffer)
    )
  )

(defun namazu-search-for-articles (group regexp)
  "Search for articles matching a Namazu regexp in a given group.
To get simpler regexp options, use `namazu-search-by-field'"
  (interactive
   (list (completing-read
	  "Group: " gnus-active-hashtb nil
	  (gnus-read-active-file-p)
	  nil
	  'gnus-group-history)
	 (read-from-minibuffer "Namazu regexp: ")))
  (namazu-select-articles group regexp))

(defun conjoin (list sep)
  (if list
      (if (cdr list)
	  (concat (car list) sep (conjoin (cdr list) sep))
	(car list))
    ""))

(defun namazu-search-by-field (group)
  "Searches the Namazu database for mails in group.
Prompts for a Namazu-style regexp or a field-specific regexp.
Field-specific regexps are:
 s - Subject:
 f - From:
 F - From: (from BBDB)
 t - To:
 m - Message-ID:
"
  (interactive (list (completing-read
		      "Group: " gnus-active-hashtb nil
		      (gnus-read-active-file-p)
		      nil
		      'gnus-group-history)))
  (let ((field (read-from-minibuffer
		"Namazu regexp or field (sfFdDtmzZ): ")))
    (cond ((> (length field) 1)
	   (namazu-select-articles group field))
	  ((equal field "s")
	   (namazu-select-articles group (concat "+subject:/"
						 (read-from-minibuffer
						  "Subject regexp: ")
						 "/")))
	  ((equal field "m")
	   (namazu-select-articles group (concat "+message-id:/"
						 (read-from-minibuffer
						  "Message-id regexp: ")
						 "/")))
	  ((equal field "f")
	   (namazu-select-articles group (concat "+from:/"
						 (read-from-minibuffer
						  "From regexp: ")
						 "/")))
	  ((equal field "t")
	   (namazu-select-articles group (concat "+to:/"
						 (read-from-minibuffer
						  "To regexp: ")
						 "/")))
	  ((equal field "F")
	   (let* ((record (bbdb-completing-read-one-record "Name (BBDB): "))
		  (emails (conjoin (aref record 6) "/ or +from:/")))
	     (namazu-select-articles group (concat "+from:/" emails "/"))))
	  (t (message (concat "Invalid selector '" field "'")))
	  ))
  )


-- 
Lars Clausen (http://shasta.cs.uiuc.edu/~lrclause)| Hårdgrim of Numenor
"I do not agree with a word that you say, but I   |----------------------------
will defend to the death your right to say it."   | Where are we going, and
    --Evelyn Beatrice Hall paraphrasing Voltaire  | what's with the handbasket?


                 reply	other threads:[~2002-08-19 15:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81wuqmx3q1.fsf@shasta.cs.uiuc.edu \
    --to=lrclause@cs.uiuc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).