123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- (require 'org)
- (defgroup org-mairix nil
- "Mairix support/integration in org."
- :tag "Org Mairix"
- :group 'org)
- (defcustom org-mairix-threaded-links t
- "Should new links be created as threaded links?
- If t, links will be stored as threaded searches.
- If nil, links will be stored as non-threaded searches."
- :group 'org-mairix
- :type 'boolean)
- (defcustom org-mairix-augmented-links nil
- "Should new links be created as augmenting searches?
- If t, links will be stored as augmenting searches.
- If nil, links will be stored as normal searches.
- Attention: When activating this option, you will need
- to remove old articles from your mairix results group
- in some other way, mairix will not do it for you."
- :group 'org-mairix
- :type 'boolean)
- (defcustom org-mairix-display-hook 'org-mairix-gnus-display-results
- "Hook to call to display the results of a successful mairix search.
- Defaults to Gnus, feel free to add your own MUAs or methods."
- :group 'org-mairix
- :type 'hook)
- (defcustom org-mairix-open-command "mairix %args% '%search%'"
- "The mairix command-line to use. If your paths are set up
- correctly, you should not need to change this.
- '%search%' will get substituted with the search expression, and
- '%args%' with any additional arguments."
- :group 'org-mairix
- :type 'string)
- (org-add-link-type "mairix" 'org-mairix-open)
- (add-hook 'org-store-link-functions 'org-mairix-store-gnus-link)
- (defun org-mairix-construct-link (message-id)
- "Construct a mairix: hyperlink based on message-id."
- (concat "mairix:"
- (if org-mairix-threaded-links "t:")
- (if org-mairix-augmented-links "a:")
- "@@"
- (org-remove-angle-brackets message-id)))
- (defun org-store-mairix-link-props (&rest plist)
- "Take a property list describing a mail, and add mairix link
- and description properties so that org can build a mairix link to
- it."
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- (let ((mid (plist-get plist :message-id)))
- (apply 'org-store-link-props
- (append plist
- (list :type "mairix"
- :link (org-mairix-construct-link mid))))
- (apply 'org-store-link-props
- (append org-store-link-plist
- (list :description (org-email-link-description))))))
- (defun org-mairix-message-send-and-exit-with-link ()
- "Function that can be assigned as an alternative sending function,
- it sends the message and then stores a mairix link to it before burying
- the buffer just like 'message-send-and-exit' does."
- (interactive)
- (message-send)
- (let* ((message-id (message-fetch-field "Message-Id"))
- (subject (message-fetch-field "Subject"))
- (link (org-mairix-construct-link message-id))
- (desc (concat "Email: '" subject "'")))
- (setq org-stored-links
- (cons (list link desc) org-stored-links)))
- (message-bury (current-buffer)))
- (defun org-mairix-open (search)
- "Function to open mairix link.
- We first need to split it into its individual parts, and then
- extract the message-id to be passed on to the display function
- before call mairix, evaluate the number of matches returned, and
- make sure to only call display of mairix succeeded in matching."
- (let* ((args ""))
- (if (equal (substring search 0 2) "t:" )
- (progn (setq search (substring search 2 nil))
- (setq args (concat args " --threads"))))
- (if (equal (substring search 0 2) "a:")
- (progn (setq search (substring search 2 nil))
- (setq args (concat args " --augment"))))
- (let ((cmdline (org-mairix-command-substitution
- org-mairix-open-command search args)))
- (print cmdline)
- (setq retval (shell-command-to-string cmdline))
- (string-match "\[0-9\]+" retval)
- (setq matches (string-to-number (match-string 0 retval)))
- (if (eq matches 0) (message "Link failed: no matches, sorry")
- (message "Link returned %d matches" matches)
- (run-hook-with-args 'org-mairix-display-hook search args)))))
- (defun org-mairix-command-substitution (cmd search args)
- "Substitute '%search%' and '%args% in mairix search command."
- (while (string-match "%search%" cmd)
- (setq cmd (replace-match search 'fixedcase 'literal cmd)))
- (while (string-match "%args%" cmd)
- (setq cmd (replace-match args 'fixedcase 'literal cmd)))
- cmd)
- (defcustom org-mairix-link-clipboard "~/.org-mairix-link"
- "Pseudo-clipboard file where mairix URLs get copied to by external
- applications in order to mimic `org-store-link'. Used by
- `org-mairix-insert-link'."
- :group 'org-mairix
- :type 'string)
- (defun org-mairix-insert-link ()
- "Insert link from file defined by `org-mairix-link-clipboard'."
- (interactive)
- (let ((bytes (cadr (insert-file-contents
- (expand-file-name org-mairix-link-clipboard)))))
- (forward-char bytes)
- (save-excursion
- (forward-char -1)
- (if (looking-at "\n")
- (delete-char 1)))))
- (defgroup org-mairix-mutt nil
- "Use mutt for mairix support in org."
- :tag "Org Mairix Mutt"
- :group 'org-mairix)
- (defcustom org-mairix-mutt-display-command
- "xterm -title 'mairix search: %search%' -e 'unset COLUMNS; mutt -f
- ~/mail/mairix -e \"push <display-message>\"' &"
- "Command to execute to display mairix search results via mutt within
- an xterm.
- '%search%' will get substituted with the search expression, and
- '%args%' with any additional arguments used in the search."
- :group 'org-mairix-mutt
- :type 'string)
- (defun org-mairix-mutt-display-results (search args)
- "Display results of mairix search in mutt, using the command line
- defined in `org-mairix-mutt-display-command'."
-
-
-
-
- (let ((cmd (org-mairix-command-substitution
- org-mairix-mutt-display-command search args))
- (tmpbufname (generate-new-buffer-name " *mairix-view*")))
- (shell-command cmd tmpbufname)
- (delete-windows-on (get-buffer tmpbufname))))
- (defgroup org-mairix-gnus nil
- "Use gnus for mairix support in org."
- :tag "Org Mairix Gnus"
- :group 'org-mairix)
- (defcustom org-mairix-gnus-results-group "nnmaildir:mairix"
- "The group that is configured to hold the mairix search results,
- which needs to be setup independently of the org-mairix integration,
- along with general mairix configuration."
- :group 'org-mairix-gnus
- :type 'string)
- (defcustom org-mairix-gnus-select-display-group-function
- 'org-mairix-gnus-select-display-group-function-gg
- "Hook to call to select the group that contains the matching articles.
- We should not need this, it is owed to a problem of gnus that people were
- not yet able to figure out, see
- http://article.gmane.org/gmane.emacs.gnus.general/65248
- http://article.gmane.org/gmane.emacs.gnus.general/65265
- http://article.gmane.org/gmane.emacs.gnus.user/9596
- for reference.
- It seems gnus needs a 'forget/ignore everything you think you
- know about that group' function. Volunteers?"
- :group 'org-mairix-gnus
- :type 'hook)
- (defun org-mairix-store-gnus-link ()
- "Store a link to the current gnus message as a Mairix search for its
- Message ID."
-
- (when (memq major-mode '(gnus-summary-mode gnus-article-mode))
- (and (eq major-mode 'gnus-article-mode) (gnus-article-show-summary))
- (let* ((article (gnus-summary-article-number))
- (header (gnus-summary-article-header article))
- (from (mail-header-from header))
- (message-id (mail-header-id header))
- (subject (gnus-summary-subject-string)))
- (org-store-mairix-link-props :from from
- :subject subject
- :message-id message-id))))
- (defun org-mairix-gnus-display-results (search args)
- "Display results of mairix search in Gnus.
- Note: This does not work as cleanly as I would like it to. The
- problem being that Gnus should simply reread the group cleanly,
- without remembering anything. At the moment it seems to be unable
- to do that -- so you're likely to see zombies floating around.
- If you can improve this, please do!"
- (if (not (equal (substring search 0 2) "m:" ))
- (error "org-mairix-gnus-display-results: display of search other than
- message-id not implemented yet"))
- (setq message-id (substring search 2 nil))
- (require 'gnus)
- (require 'gnus-sum)
-
-
-
-
- (funcall (cdr (assq 'gnus org-link-frame-setup)))
- (if gnus-other-frame-object (select-frame gnus-other-frame-object))
-
-
-
-
-
-
-
-
-
-
-
-
- (run-hook-with-args 'org-mairix-gnus-select-display-group-function)
- (gnus-summary-select-article
- nil t t (car (gnus-find-matching-articles "message-id" message-id))))
- (defun org-mairix-gnus-select-display-group-function-gg ()
- "Georg's hack to select a group that gnus (falsely) believes to be
- empty to then call rebuilding of the summary. It leaves zombies of
- old searches around, though."
- (gnus-group-quick-select-group 0 org-mairix-gnus-results-group)
- (gnus-group-clear-data)
- (gnus-summary-reselect-current-group t t))
- (defun org-mairix-gnus-select-display-group-function-bzg ()
- "This is the classic way the org mode is using, and it seems to be
- using better for Bastien, so it may work for you."
- (gnus-group-clear-data org-mairix-gnus-results-group)
- (gnus-group-read-group t nil org-mairix-gnus-results-group))
- (provide 'org-mairix)
|