Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Namazu, BBDB, Gnus
@ 2002-08-19 15:33 Lars Clausen
  0 siblings, 0 replies; only message in thread
From: Lars Clausen @ 2002-08-19 15:33 UTC (permalink / 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?


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-08-19 15:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-19 15:33 Namazu, BBDB, Gnus Lars Clausen

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).