Wanderlust: refile (move) to archive folder by year

Christian Kruse

Since I recently switched to Emacs/Wanderlust for email, I've been looking for a solution to easily refile (move) a mail into an archive folder by year. For example, mails sent 2014 should be moved to Archive/2014. By default, this is not possible. But gladly we can enhance Emacs and accordingly Wanderlust as well by elisp. So I wrote a small defun to do exactly that:

(defun ck-refile-to-archive ()
  "Refile current message to archive folder"

  (let ((msg-num (wl-summary-message-number))
    (setq entity (elmo-message-entity wl-summary-buffer-elmo-folder msg-num))
    (setq msg-date (elmo-message-entity-field entity 'date))
    (setq msg-date (format-time-string "%Y" msg-date))

    (if (string-match "Termitel" (wl-summary-buffer-folder-name))
        (setq folder (concat ".Termitel/Archiv." msg-date))
      (setq folder (concat ".Defunct/Archiv." msg-date)))
    (wl-summary-refile (wl-summary-message-number) folder)
    (message "Refiled to %s" folder)))

This gets the message from the index, reads its date and refiles it to the Defunct/Archiv.2014 or Defunct/Archiv.2014 folder, depending on what account I am currently using: Defunct (private) or Termitel (work). Keep in mind that subfolders in IMAP are represented by dots, not slashes.