2008-03-21 16:10:23 +00:00
|
|
|
;;; org-vm.el --- Support for links to VM messages from within Org-mode
|
2008-03-14 17:22:03 +00:00
|
|
|
|
2012-03-17 15:31:04 +00:00
|
|
|
;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
|
2008-03-14 17:22:03 +00:00
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
|
|
|
;;
|
2012-03-19 20:38:12 +00:00
|
|
|
;; Support for IMAP folders added
|
|
|
|
;; by Konrad Hinsen <konrad dot hinsen at fastmail dot net>
|
|
|
|
;; Requires VM 8.2.0a or later.
|
|
|
|
;;
|
2008-03-14 17:22:03 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 12:45:52 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-03-14 17:22:03 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 12:45:52 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-03-14 17:22:03 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 12:45:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2008-03-14 17:22:03 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
2008-03-21 16:10:23 +00:00
|
|
|
;; This file implements links to VM messages and folders from within Org-mode.
|
2008-03-14 17:22:03 +00:00
|
|
|
;; Org-mode loads this module by default - if this is not what you want,
|
|
|
|
;; configure the variable `org-modules'.
|
|
|
|
|
2008-03-21 16:10:23 +00:00
|
|
|
;;; Code:
|
|
|
|
|
2008-03-14 17:22:03 +00:00
|
|
|
(require 'org)
|
|
|
|
|
|
|
|
;; Declare external functions and variables
|
2008-11-06 15:31:35 +00:00
|
|
|
(declare-function vm-preview-current-message "ext:vm-page" ())
|
2008-03-14 17:22:03 +00:00
|
|
|
(declare-function vm-follow-summary-cursor "ext:vm-motion" ())
|
|
|
|
(declare-function vm-get-header-contents "ext:vm-summary"
|
|
|
|
(message header-name-regexp &optional clump-sep))
|
|
|
|
(declare-function vm-isearch-narrow "ext:vm-search" ())
|
|
|
|
(declare-function vm-isearch-update "ext:vm-search" ())
|
|
|
|
(declare-function vm-select-folder-buffer "ext:vm-macro" ())
|
|
|
|
(declare-function vm-su-message-id "ext:vm-summary" (m))
|
|
|
|
(declare-function vm-su-subject "ext:vm-summary" (m))
|
|
|
|
(declare-function vm-summarize "ext:vm-summary" (&optional display raise))
|
2012-03-19 20:38:12 +00:00
|
|
|
(declare-function vm-imap-folder-p "ext:vm-save" ())
|
|
|
|
(declare-function vm-imap-find-spec-for-buffer "ext:vm-imap" (buffer))
|
|
|
|
(declare-function vm-imap-folder-for-spec "ext:vm-imap" (spec))
|
|
|
|
(declare-function vm-imap-parse-spec-to-list "ext:vm-imap" (spec))
|
|
|
|
(declare-function vm-imap-spec-for-account "ext:vm-imap" (account))
|
2008-03-14 17:22:03 +00:00
|
|
|
(defvar vm-message-pointer)
|
|
|
|
(defvar vm-folder-directory)
|
|
|
|
|
|
|
|
;; Install the link type
|
|
|
|
(org-add-link-type "vm" 'org-vm-open)
|
2012-03-19 20:38:12 +00:00
|
|
|
(org-add-link-type "vm-imap" 'org-vm-imap-open)
|
2008-03-14 17:22:03 +00:00
|
|
|
(add-hook 'org-store-link-functions 'org-vm-store-link)
|
|
|
|
|
|
|
|
;; Implementation
|
|
|
|
(defun org-vm-store-link ()
|
2008-03-21 16:10:23 +00:00
|
|
|
"Store a link to a VM folder or message."
|
2011-02-12 18:39:06 +00:00
|
|
|
(when (and (or (eq major-mode 'vm-summary-mode)
|
|
|
|
(eq major-mode 'vm-presentation-mode))
|
|
|
|
(save-window-excursion
|
2011-02-14 10:14:25 +00:00
|
|
|
(vm-select-folder-buffer) buffer-file-name))
|
2008-03-14 17:22:03 +00:00
|
|
|
(and (eq major-mode 'vm-presentation-mode) (vm-summarize))
|
|
|
|
(vm-follow-summary-cursor)
|
|
|
|
(save-excursion
|
|
|
|
(vm-select-folder-buffer)
|
|
|
|
(let* ((message (car vm-message-pointer))
|
2012-03-19 20:38:12 +00:00
|
|
|
(subject (vm-su-subject message))
|
2008-03-14 17:22:03 +00:00
|
|
|
(to (vm-get-header-contents message "To"))
|
|
|
|
(from (vm-get-header-contents message "From"))
|
2012-03-19 20:38:12 +00:00
|
|
|
(message-id (vm-su-message-id message))
|
|
|
|
(link-type (if (vm-imap-folder-p) "vm-imap" "vm"))
|
2010-09-23 16:11:38 +00:00
|
|
|
(date (vm-get-header-contents message "Date"))
|
|
|
|
(date-ts (and date (format-time-string
|
|
|
|
(org-time-stamp-format t)
|
|
|
|
(date-to-time date))))
|
|
|
|
(date-ts-ia (and date (format-time-string
|
|
|
|
(org-time-stamp-format t t)
|
|
|
|
(date-to-time date))))
|
2012-03-19 20:38:12 +00:00
|
|
|
folder desc link)
|
|
|
|
(if (vm-imap-folder-p)
|
|
|
|
(let ((spec (vm-imap-find-spec-for-buffer (current-buffer))))
|
|
|
|
(setq folder (vm-imap-folder-for-spec spec)))
|
|
|
|
(progn
|
|
|
|
(setq folder (abbreviate-file-name buffer-file-name))
|
|
|
|
(if (and vm-folder-directory
|
|
|
|
(string-match (concat "^" (regexp-quote vm-folder-directory))
|
|
|
|
folder))
|
|
|
|
(setq folder (replace-match "" t t folder)))))
|
|
|
|
(setq message-id (org-remove-angle-brackets message-id))
|
|
|
|
(org-store-link-props :type link-type :from from :to to :subject subject
|
2008-03-14 17:22:03 +00:00
|
|
|
:message-id message-id)
|
2010-09-23 16:11:38 +00:00
|
|
|
(when date
|
|
|
|
(org-add-link-props :date date :date-timestamp date-ts
|
|
|
|
:date-timestamp-inactive date-ts-ia))
|
2008-03-14 17:22:03 +00:00
|
|
|
(setq desc (org-email-link-description))
|
2012-03-19 20:38:12 +00:00
|
|
|
(setq link (org-make-link (concat link-type ":") folder "#" message-id))
|
2008-03-15 20:34:06 +00:00
|
|
|
(org-add-link-props :link link :description desc)
|
|
|
|
link))))
|
2008-03-14 17:22:03 +00:00
|
|
|
|
|
|
|
(defun org-vm-open (path)
|
2008-03-21 16:10:23 +00:00
|
|
|
"Follow a VM message link specified by PATH."
|
2008-03-14 17:22:03 +00:00
|
|
|
(let (folder article)
|
|
|
|
(if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
|
|
|
|
(error "Error in VM link"))
|
|
|
|
(setq folder (match-string 1 path)
|
|
|
|
article (match-string 3 path))
|
2008-03-21 16:10:23 +00:00
|
|
|
;; The prefix argument will be interpreted as read-only
|
2008-03-14 17:22:03 +00:00
|
|
|
(org-vm-follow-link folder article current-prefix-arg)))
|
|
|
|
|
|
|
|
(defun org-vm-follow-link (&optional folder article readonly)
|
|
|
|
"Follow a VM link to FOLDER and ARTICLE."
|
|
|
|
(require 'vm)
|
|
|
|
(setq article (org-add-angle-brackets article))
|
|
|
|
(if (string-match "^//\\([a-zA-Z]+@\\)?\\([^:]+\\):\\(.*\\)" folder)
|
|
|
|
;; ange-ftp or efs or tramp access
|
|
|
|
(let ((user (or (match-string 1 folder) (user-login-name)))
|
|
|
|
(host (match-string 2 folder))
|
|
|
|
(file (match-string 3 folder)))
|
|
|
|
(cond
|
|
|
|
((featurep 'tramp)
|
|
|
|
;; use tramp to access the file
|
|
|
|
(if (featurep 'xemacs)
|
|
|
|
(setq folder (format "[%s@%s]%s" user host file))
|
|
|
|
(setq folder (format "/%s@%s:%s" user host file))))
|
|
|
|
(t
|
|
|
|
;; use ange-ftp or efs
|
|
|
|
(require (if (featurep 'xemacs) 'efs 'ange-ftp))
|
|
|
|
(setq folder (format "/%s@%s:%s" user host file))))))
|
|
|
|
(when folder
|
|
|
|
(funcall (cdr (assq 'vm org-link-frame-setup)) folder readonly)
|
|
|
|
(when article
|
2012-03-19 20:38:12 +00:00
|
|
|
(org-vm-select-message (org-add-angle-brackets article)))))
|
|
|
|
|
|
|
|
(defun org-vm-imap-open (path)
|
|
|
|
"Follow a VM link to an IMAP folder"
|
|
|
|
(require 'vm-imap)
|
|
|
|
(when (string-match "\\([^:]+\\):\\([^#]+\\)#?\\(.+\\)?" path)
|
|
|
|
(let* ((account-name (match-string 1 path))
|
|
|
|
(mailbox-name (match-string 2 path))
|
|
|
|
(message-id (match-string 3 path))
|
|
|
|
(account-spec (vm-imap-parse-spec-to-list
|
|
|
|
(vm-imap-spec-for-account account-name)))
|
|
|
|
(mailbox-spec (mapconcat 'identity
|
|
|
|
(append (butlast account-spec 4)
|
|
|
|
(cons mailbox-name
|
|
|
|
(last account-spec 3)))
|
|
|
|
":")))
|
|
|
|
(funcall (cdr (assq 'vm-imap org-link-frame-setup))
|
|
|
|
mailbox-spec)
|
|
|
|
(when message-id
|
|
|
|
(org-vm-select-message (org-add-angle-brackets message-id))))))
|
|
|
|
|
|
|
|
(defun org-vm-select-message (message-id)
|
|
|
|
"Go to the message with message-id in the current folder."
|
|
|
|
(require 'vm-search)
|
|
|
|
(sit-for 0.1)
|
|
|
|
(vm-select-folder-buffer)
|
|
|
|
(widen)
|
|
|
|
(let ((case-fold-search t))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (not (re-search-forward
|
|
|
|
(concat "^" "message-id: *" (regexp-quote message-id))))
|
|
|
|
(error "Could not find the specified message in this folder"))
|
|
|
|
(vm-isearch-update)
|
|
|
|
(vm-isearch-narrow)
|
|
|
|
(vm-preview-current-message)
|
|
|
|
(vm-summarize)))
|
2008-03-14 17:22:03 +00:00
|
|
|
|
|
|
|
(provide 'org-vm)
|
|
|
|
|
2012-03-19 20:38:12 +00:00
|
|
|
|
|
|
|
|
2008-03-14 17:22:03 +00:00
|
|
|
;;; org-vm.el ends here
|