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:

<pre class=”brush: elisp”>(defun ck-refile-to-archive () “Refile current message to archive folder” (interactive) (let ((msg-num (wl-summary-message-number)) (entity) (msg-date) (folder)) (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) (wl-summary-next) (message “Refiled to %s” folder)))</pre></code><p> This gets the message from the index, reads its date and refiles it to the <code>Defunct/Archiv.2014</code> or <code>Defunct/Archiv.2014</code> 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.</p>