;; -*- mode: emacs-lisp -*-

;;; MY IDENTITY ===============================================================

(setq user-full-name "Phil Sung")
(setq user-mail-address "psung@mydomain.com")

;;; WHERE TO STORE MAIL =======================================================

(setq vm-folder-directory "~/mail")
(setq vm-primary-inbox "~/mail/inbox")
(setq mail-archive-file-name "~/mail/sent")

;;; HOW TO GET MAIL ===========================================================

;; Associate local mailboxes with mail sources
(setq vm-spool-files
      '(("~/mail/system" "/var/spool/mail/phil" "~/mail/system.crash")
        ("~/mail/inbox" "pop-ssl:pop.gmail.com:995:pass:YOUR_USERNAME:*"
         "~/mail/inbox.crash")))

;; Configure outbound mail (SMTP)
(setq smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
      smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-default-smtp-server "smtp.gmail.com"
      send-mail-function 'smtpmail-send-it
      message-send-mail-function 'smtpmail-send-it
      smtpmail-smtp-service 587
      smtpmail-auth-credentials '(("smtp.gmail.com" 587
                                   "YOUR_USERNAME@gmail.com" nil)))

(setq password-cache-expiry 86400)      ; Time (in sec) to cache SMTP password

(setq vm-stunnel-program "stunnel4")

;;; COMPOSING AND SENDING MAIL ================================================

;; In outgoing mail, write "From" field as "My Name <name@host.net>"
(setq mail-from-style 'angles)

(setq mail-self-blind t)                ; BCC self on all messages.

(setq mail-interactive nil)             ; Background sending mail.

;;; READING MAIL ==============================================================

(setq vm-delete-empty-folders nil)

(setq-default vm-summary-show-threads t) ; Show threaded view by default

(setq vm-preview-lines nil)             ; Don't preview, just display msg

(setq vm-delete-after-archiving t)
(setq vm-delete-after-saving t)
(setq vm-move-after-deleting t)

;; Don't let VM create new frames for anything!
(setq vm-frame-per-completion nil)
(setq vm-frame-per-composition nil)
(setq vm-frame-per-edit nil)
(setq vm-frame-per-folder nil)
(setq vm-frame-per-folders-summary nil)
(setq vm-frame-per-help nil)
(setq vm-frame-per-summary nil)

;;; CHARSETS AND ENCODINGS ====================================================

;; Convert UTF-8 messages to an 8-bit encoding so they can be displayed in
;; messages inline. Otherwise, you will be prompted to save the message to a
;; file.
(setq vm-mime-charset-converter-alist
      '(("utf-8" "iso-8859-1" "iconv -c -f utf-8 -t iso-8859-1")))

(and (boundp 'vm-mime-default-face-charsets)
     (progn
       (add-to-list 'vm-mime-default-face-charsets "Windows-1251")
       (add-to-list 'vm-mime-default-face-charsets "Windows-1252")
       (add-to-list 'vm-mime-default-face-charsets "Windows-1257")))

;;; VFOLDERS AND FILING =======================================================

;; Ignore case when matching virtual folders and archive targets below.
;; Otherwise we have to define all sorts of hairy regexps.
(setq vm-virtual-check-case-fold-search t)
(setq vm-auto-folder-case-fold-search t)

(setq vm-virtual-folder-alist
      '(("reuse" (("inbox") (header "reuse@mit\.edu")))
        ("intrepid-changes" (("inbox") (header "intrepid-changes\.lists\.ubuntu\.com")))
        ("launchpad" (("inbox") (header "X-Generated-By: Launchpad")))
        ("ubuntu" (("inbox") (header "ubuntu-.*\.lists\.ubuntu\.com")))
        ("emacs" (("inbox")
                  (header "\\(help-gnu-emacs\\|emacs-devel\\|emacs-pretest-bug\\)\.gnu\.org")))
        ("xemacs" (("inbox") (header "xemacs-beta\.xemacs\.org")))
        ("openmoko" (("inbox")
                     (header "\\(devel\\|support\\|community\\)\.lists\.openmoko\.org")))
        ("ddmg" (("inbox")
                 (author-or-recipient "\\(colleague1\\|colleague2\\)@example\.com")))))

(setq pps-unimportant-virtual-folders
      '("launchpad" "intrepid-changes" "ubuntu" "openmoko" "emacs" "xemacs"))
;; Make an additional virtual folder, "nonjunk" which catches any message not
;; in the above specified virtual folders.
(add-to-list
 'vm-virtual-folder-alist
 `("nonjunk"
   (("inbox")
    (not (or ,@(mapcar (lambda (c)
                         (second (second (assoc c vm-virtual-folder-alist))))
                       pps-unimportant-virtual-folders))))))

(setq vm-auto-folder-alist
      '(("X-BeenThere"
         ("reuse@mit\.edu" . "reuse"))
        ("From"
         ("\\(colleague1\\|colleague2\\)@example\.com" . "ddmg"))
        ("List-Id"
         ("intrepid-changes\.lists\.ubuntu\.com" . "intrepid-changes")
         ("ubuntu-.*\.lists\.ubuntu\.com" . "ubuntu")
         ("\\(help-gnu-emacs\\|emacs-devel\\|emacs-pretest-bug\\)\.gnu\.org" . "emacs")
         ("xemacs-beta\.xemacs\.org" . "xemacs")
         ("\\(devel\\|support\\|community\\)\.lists\.openmoko\.org" . "openmoko"))
        ("X-Generated-By"
         ("Launchpad" . "launchpad"))
        ("To"
         (".*" . "general"))))

;;; BBDB ======================================================================

(and (fboundp 'bbdb-insinuate-vm)
     (bbdb-insinuate-vm))

;; Don't create new entries for people unless explicitly asked to.
(setq bbdb/mail-auto-create-p nil)
;; Only attempt to complete name or first email address. This cuts down on
;; extraneous completions when a person has many email addresses.
(setq bbdb-completion-type 'primary-or-name)
;; Tell BBDB who I am.
(setq bbdb-user-mail-names "(psung@(alum\.)mit\.edu)")
