(setq jk-header-intro-mapping '(("AW\\|SV\\|RE" "Re") ("WG" "Fwd"))) (defun jk-match-header-intro (mapping intro) (if mapping (if (string-match (car (car mapping)) intro) (car (cdr (car mapping))) (jk-match-header-intro (cdr mapping) intro)) nil)) (setq jk-header-change-all t) (defun jk-change-outlook-headers () "Change Subject according to jk-header-intro-mapping in mails produced by Microsoft Outlook." (save-excursion (goto-char (point-min)) (if (or jk-header-change-all (re-search-forward "^X-Mailer: \\(Internet Mail Service\\|Microsoft\\|Outlook\\)" nil t)) (progn (goto-char (point-min)) (if (re-search-forward "^\\(Subject: \\(=\\?[^?]+\\?[^?]+\\?\\)?\\)\\(\\w\\{1,3\\}\\)\\(:\\|=3A\\)" nil t) (let ((regexp-state (match-data))) (let ((replacement (jk-match-header-intro jk-header-intro-mapping (match-string 3)))) (if replacement (progn (set-match-data regexp-state) (replace-match (concat (match-string 1) replacement (match-string 4)) t)))))))))) (add-hook 'nnmail-prepare-incoming-header-hook 'jk-change-outlook-headers)