[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mapping over Zmail to/from headers



Based on a suggestion by Gumby, I modified the Show Corresponders
command to use ZWEI:DEFCOM. Now all you have to do is type h-Z
in Zmail and a buffer corresponders.text will contain the results.
Just goes to show you that there is an infinite amount of hacking
one can do once one gets started on such things.
        Jeff

;;; -*- Mode: LISP; Package: USER; Base: 10; Syntax: Common-lisp -*-

(zwei:defcom com-list-corresponders
             "Puts a list of all network address appearing in to/cc/from
fields in the current Zmail sequence into an editor buffer"
             ()
  (let ((corresponders (make-hash-table :test #'equal)))
    (send zwei:*sequence* :map-over-msgs
          (lambda (msg)
            (loop for from in (getf (zwei:msg-status msg) :from)
                  for id = (list (string-upcase (getf from :name))
                                 (map 'list
                                      (lambda (thing)
                                        (if (stringp thing)
                                            (string-upcase thing)
                                            thing))
                                      (getf from :host)))
                  for who = (getf from :original-string)
                  when (null (gethash id corresponders))
                    do (setf (gethash id corresponders) who))
            (loop for to in (getf (zwei:msg-status msg) :to)
                  for id = (list (string-upcase (getf to :name))
                                 (map 'list
                                      (lambda (thing)
                                        (if (stringp thing)
                                            (string-upcase thing)
                                            thing))
                                      (getf to :host)))
                  for who = (getf to :original-string)
                  when (null (gethash id corresponders))
                    do (setf (gethash id corresponders) who))
            (loop for cc in (getf (zwei:msg-status msg) :cc)
                  for id = (list (string-upcase (getf cc :name))
                                 (map 'list
                                      (lambda (thing)
                                        (if (stringp thing)
                                            (string-upcase thing)
                                            thing))
                                      (getf cc :host)))
                  for who = (getf cc :original-string)
                  when (null (gethash id corresponders))
                    do (setf (gethash id corresponders) who))))
    (with-open-stream
     (buffer (zwei:make-file-buffer-stream
              (make-pathname :name "CORRESPONDERS"
                             :type "TEXT"
                             :defaults (user-homedir-pathname))))
      (loop for who being the hash-elements of corresponders
            do (format buffer "~&~A" who))))
  zwei:dis-none)

(zwei:set-comtab zwei:*zmail-comtab* '(#\hyper-z com-list-corresponders))