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

Re: wl newbie, various questions



At Fri, 15 Jun 2012 18:58:15 -0700,
Erik Hetzner wrote:
> Hi Francesco,
> 
> The variable is wl-summary-buffer-folder-name.

Yes, this works well. In the end, I ended up preferring the
"traditional" workflow, so I think I won't refile automatically on
sync, or at least not for the moment.

In case somebody is interested, here is my current configuration. I
learnt elisp while writing it, so it's probably not that idiomatic -
but it works!

-------------8<-------------

;;; ---------------------------------------------------------------------------
;;; Utils

(defun lookup (key params &optional default)
  (let ((value (assoc key params)))
    (if (consp value) (cdr value) default)))

(defun any (fun list)
  (if (null list)
      nil
    (or (funcall fun (car list))
        (any fun (cdr list)))))

(defmacro defun-params (fun-name params &rest body)
  "Macro to create functions that take a dictionary of
parameters, possibly with default values. Each key is bound to a
variable in that can be used in the body. See `create-account'
for an example."
  (let ((params-var (make-symbol "params")))
    (defun format-params (params1)
      (mapcar (lambda (param)
                (let ((name    (cond ((atom param) param)
                                     ((consp param) (car param))))
                      (default (cond ((atom param) nil)
                                     ((consp param) (cdr param)))))
                  `(,name (lookup ',name ,params-var ,default))))
              params))
    `(defun ,fun-name (,params-var)
       (let* ,(format-params params) ,@body))))

;;; ---------------------------------------------------------------------------
;;; To "display" html

(require 'w3m)
(require 'mime-w3m)

;;; ---------------------------------------------------------------------------
;;; Accounts

;;; Initial values for the vars modified by the account function
(setq wl-user-mail-address-list nil
      wl-dispose-folder-alist '(("^-" . remove)
                                ("^@" . remove))
      wl-draft-config-alist nil
      wl-template-alist nil
      wl-subscribed-mailing-list nil
      wl-refile-rule-alist nil)

(defun account-folder (server user port folder)
  (concat "%" folder ":\"" user "\"/clear@" server ":"  (number-to-string port) "!"))

;;; TODO: I'd like this to return some data type that can be used in other
;;; functions rather than doing everything monolithically here.
(defun-params create-account (account-name
                              user
                              domain
                              (address      . (concat user "@" domain))
                              (imap         . (concat "imap." domain))
                              (imap-port    . 993)
                              (smtp         . (concat "smtp." domain))
                              (smtp-port    . 587)
                              (inbox        . "INBOX")
                              (trash        . "Trash")
                              (draft        . "Drafts")
                              (sent         . "Sent")
                              (trash-match  . (regexp-quote domain))
                              (real-name    . "Francesco Mazzoli")
                              (draft-config .
                               `(string-match ,user wl-draft-parent-folder))
                              mailing-lists)
  (defun this-folder (folder)
    (account-folder imap user imap-port folder))

  (add-to-list 'wl-user-mail-address-list address)
  (add-to-list 'wl-dispose-folder-alist `(,trash-match . ,(this-folder trash)))

  (add-to-list 'wl-draft-config-alist `(,draft-config (template . ,account-name)))

  (add-to-list 'wl-template-alist
               `(,account-name (wl-from . ,(concat real-name " <" address ">"))
                               ("From" . wl-from)
                               (wl-smtp-posting-user . ,user)
                               (wl-smtp-posting-server . ,smtp)
                               (wl-smtp-authenticate-type ."plain")
                               (wl-smtp-connection-type . 'starttls)
                               (wl-smtp-posting-port . ,smtp-port)
                               (wl-local-domain . ,domain)
                               (wl-message-id-domain . ,domain)
                               (wl-fcc . ,(this-folder sent))
                               (wl-draft-folder . ,(this-folder sent))))

  ;; TODO: Right now this does not work if we have the same ML in different
  ;; account
  (dolist (mailing-list mailing-lists)
    (let ((ml-address (car mailing-list))
          (ml-dest    (cdr mailing-list)))
      (add-to-list 'wl-subscribed-mailing-list ml-address)
      (add-to-list 'wl-refile-rule-alist
                   `(("To" "Cc")
                     (,(regexp-quote ml-address) . ,(this-folder ml-dest))))))

  't)

;; Example account

(create-account
 '((account-name . "foo")
   (user         . "bar")
   (domain       . "gmail.com")
   (trash        . "[Gmail]/Trash")
   (draft        . "[Gmail]/Draft")
   (sent         . "[Gmail]/Sent Mail")
   (real-name    . "Francesco")
   (mailing-lists . (("haskell-cafe@haskell.org" . "MLs/haskell-cafe")))))

;;; ---------------------------------------------------------------------------
;;; Headers

(setq wl-message-ignored-field-list '("^.*:")
      wl-message-visible-field-list '("^\\(To\\|Cc\\):"
                                      "^Subject:"
                                      "^\\(From\\|Reply-To\\):"
                                      "^Organization:"
                                      "^Message-Id:"
                                      "^\\(Posted\\|Date\\):"
                                      "^[xX]-[Ff]ace:")
      wl-message-sort-field-list '("^From"
                                   "^Organization:"
                                   "^Subject:"
                                   "^Date:"
                                   "^To:"
                                   "^Cc:"))
;;; ---------------------------------------------------------------------------
;;; Miscellanea

(setq ssl-program-name "gnutls-cli"
      ssl-program-arguments
      '("--port" service
        "--insecure"
        "--x509cafile" "/etc/ssl/certs/ca-certificates.crt"
        host)

      wl-fcc-force-as-read t

      wl-stay-folder-window t

      wl-summary-width 150

      wl-summary-auto-refile-skip-marks nil)

;; select correct email address when we _start_ writing a draft.
(add-hook 'wl-mail-setup-hook 'wl-draft-config-exec)

;;; ---------------------------------------------------------------------------
;;; bbdb
(require 'bbdb-wl)

(bbdb-wl-setup)
;; enable pop-ups
(setq bbdb-use-pop-up t)
;; auto collection
(setq bbdb/mail-auto-create-p t)
;; exceptional folders against auto collection
;; (setq bbdb-wl-ignore-folder-regexp "^@")
(setq signature-use-bbdb t)
(setq bbdb-north-american-phone-numbers-p nil)
;; shows the name of bbdb in the summary :-)
(setq wl-summary-from-function 'bbdb-wl-from-func)
;; automatically add mailing list fields
(add-hook 'bbdb-notice-hook 'bbdb-auto-notes-hook)
(setq bbdb-auto-notes-alist '(("X-ML-Name" (".*$" ML 0))))

------------->8-------------