Dear org-mode maintainers, I have been trying to include links to rmail folders in my .org file, and found that following those would lead to "Message not found" unless (1) the link was to the last message in the folder; and (2) I ensured that Message-ID was not hidden (the latter also was necessary to be able to copy links with C-cl).
Trying to understand org-rmail-follow-link in org-rmail.el, the behaviour is consistent with the buffer not being widen'd, but I am not sure why that didn't happen. I did find that the rewrite below corrected the bug -- difference with original follows; it is partially a reversion to an older version I found at http://braeburn.aquamacs.org/code/master/lisp/org/org-rmail.el Unfortunately, I understand what I'm doing far too poorly to be sure this is the correct solution... Thanks, all best regards, Marten van Kerkwijk (defun org-rmail-follow-link (folder article) "Follow an Rmail link to FOLDER and ARTICLE." (require 'rmail) (setq article (org-add-angle-brackets article)) (let (message-number buff) (save-excursion (save-window-excursion (rmail (if (string= folder "RMAIL") rmail-file-name folder)) (setq buff (current-buffer) message-number (with-current-buffer rmail-view-buffer (save-restriction (widen) (goto-char (point-max)) (if (re-search-backward (concat "^Message-ID:\\s-+" (regexp-quote (or article ""))) nil t) ;; This is an rmail "debugging" function. :( (with-current-buffer buff (rmail-what-message)))))))) (if message-number (progn (rmail (if (string= folder "RMAIL") rmail-file-name folder)) (rmail-show-message message-number) message-number) (error "Message not found")))) The difference with the original: mhvk@swan:~/emacs$ diff -w org-rmail.el~ org-rmail.el 94c94 < (let (message-number) --- > (let (message-number buff) 98c98,100 < (setq message-number --- > (setq buff (current-buffer) > message-number > (with-current-buffer rmail-view-buffer 106c108,110 < (rmail-what-message)))))) --- > ;; This is an rmail "debugging" function. :( > (with-current-buffer buff > (rmail-what-message)))))))) Emacs : GNU Emacs 24.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2) of 2012-06-15 on zelenka, modified by Debian Package: Org-mode version 7.8.11 current state: ============== (setq org-export-preprocess-before-selecting-backend-code-hook '(org-beamer-select-beamer-code) org-tab-first-hook '(org-hide-block-toggle-maybe org-src-native-tab-command-maybe org-babel-hide-result-toggle-maybe) org-speed-command-hook '(org-speed-command-default-hook org-babel-speed-command-hook) org-occur-hook '(org-first-headline-recenter) org-metaup-hook '(org-babel-load-in-session-maybe) org-export-preprocess-before-normalizing-links-hook '(org-remove-file-link-modifiers) org-confirm-shell-link-function 'yes-or-no-p org-export-latex-final-hook '(org-beamer-amend-header org-beamer-fix-toc org-beamer-auto-fragile-frames org-beamer-place-default-actions-for-lists) org-export-latex-after-initial-vars-hook '(org-beamer-after-initial-vars) org-default-notes-file "~/things_to_think_about/gtd.org" org-after-todo-state-change-hook '(org-clock-out-if-current) org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-configure-edit-buffer) org-agenda-before-write-hook '(org-agenda-add-entry-text) org-babel-pre-tangle-hook '(save-buffer) org-mode-hook '(#[nil "\300\301\302\303\304$\207" [org-add-hook change-major-mode-hook org-show-block-all append local] 5] #[nil "\300\301\302\303\304$\207" [org-add-hook change-major-mode-hook org-babel-show-result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes (lambda nil (define-key org-mode-map [home] nil) (define-key org-mode-map [end] nil)) ) org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point org-babel-execute-safely-maybe) org-directory "~/things_to_think_about/" org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers org-cycle-show-empty-lines org-optimize-window-after-visibility-change) org-export-latex-format-toc-function 'org-export-latex-format-toc-default org-export-blocks '((src org-babel-exp-src-block nil) (export-comment org-export-blocks-format-comment t) (ditaa org-export-blocks-format-ditaa nil) (dot org-export-blocks-format-dot nil)) org-export-first-hook '(org-beamer-initialize-open-trackers) org-export-interblocks '((src org-babel-exp-non-block-elements)) org-enable-priority-commands nil org-confirm-elisp-link-function 'yes-or-no-p org-metadown-hook '(org-babel-pop-to-session-maybe) org-agenda-files '("~/things_to_think_about/gtd.org") org-clock-out-hook '(org-clock-remove-empty-clock-drawer) )