Fix links to my homepage.
[worg.git] / code / elisp / org-exchange-capture.el
blob4cd6cd2fc093548a6dd67c171cc9d35ca6fe661e
1 ;; org-exchange-capture.el, v0.0.1
2 ;; written by: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
3 ;; License: GPLv3+
5 (require 'org-capture)
7 ;; turn the e-mails sent MS-Exchange about invitation/appointments into org-TODOs
8 ;; using 'org-capture'.
10 ;; The idea is that you select (mark) the parts of the email you want to add to
11 ;; your org-todo item, and then invoke M-x org-exchange-capture-invitation
13 ;; Some caveats:
15 ;; - obviously, this is just a one-way copy, it won't make you 'accept' an
16 ;; invitation, nor does it get any updates
18 ;; - it seems to work with the emails I get from Exchange (I've encountered two
19 ;; different kinds). But there may be more; at least the ones I get that are
20 ;; in English, there are other versions as well. I'd be interested in
21 ;; extending the regexps with more cases.
23 ;; - it does not take time-zones into account (yet)
25 ;; NOTE:
26 ;; It does NOT handle yet:
27 ;; When: 12.08.2010 12:00-14:00 (GMT+02:00) Helsinki, ...
28 ;; When: \\([0-9]\\{2\\}\.[0-9]\\{2\\}\.[0-9]\\{4\\}\\)
30 ;; When: 20. syyskuuta 2010 12:00-12:45 (GMT+02:00) Helsinki, ....
32 ;; When: Occurs every Thursday effective 19.08.2010 from 14:00 to 15:30
33 ;; (GMT+02:00) Helsinki, ...
35 ;; - it requires org-capture, which is fairly new; it should be easy to support
36 ;; org-remember as well though. Also, I only tested with Wanderlust as e-mail
37 ;; client; it *should* work with others as well though...
39 ;; Note that that the message buffer must be the active buffer;
40 ;; ie. it won't work in the 'Summary' (Wanderlust)
42 (defun djcb-exchange-invite-time-to-org-date()
43 "try to to find the Time/Date from an Exchange-invitation
44 e-mail in the current buffer, and convert it into an org-mode
45 date, or `nil' if it's not found."
46 "get the time/date of an Outlook invite in org-mode notation"
47 (let ((date) (time-begin) (time-end))
48 (save-excursion
49 (save-match-data
50 (beginning-of-buffer)
51 (if (re-search-forward
52 (concat "^When: \\([0-9]+ [a-z]+,? [0-9]\\{4\\}\\) "
53 "\\([0-9]+:[0-9]+\\)-\\([0-9]+:[0-9]+\\)") nil t 1)
54 (progn
55 (setq
56 date (parse-time-string (match-string-no-properties 1))
57 time-begin (match-string-no-properties 2)
58 time-end (match-string-no-properties 3))
59 (format "<%d-%02d-%02d %s--%s>"
60 (elt date 5) (elt date 4) (elt date 3)
61 time-begin time-end))
62 (message "No match")
63 nil)))))
65 (defun djcb-exchange-invite-subject()
66 "get the subject of an MS-Exchange invite e-mail in the current
67 buffer"
68 (save-excursion
69 (save-match-data
70 (beginning-of-buffer)
71 (when (re-search-forward "^Subject: \\(.*\\)" nil t 1)
72 (match-string-no-properties 1)))))
74 (defun org-exchange-capture-invitation ()
75 "capture the MS-Exchange invite e-mail in buffer into an
76 org-mode agenda item using the org-capture system. For this to
77 work, you'll need to add to your `org-capture-templates' an item
78 with a shortcut key of 'E', e.g.
80 (\"E\" \"ExchangeInvite\" entry
81 (file+headline \"todo.org\" \"Meetings\")
82 \"* TODO %c\\n\")
84 any text you select (mark) in the buffer will be added to to
85 captured TODO; thus you can add the relevant details to the org TODO item.
87 (interactive)
88 (let( (time (djcb-exchange-invite-time-to-org-date))
89 (title (djcb-exchange-invite-subject))
90 (txt
91 (if (use-region-p) (buffer-substring-no-properties (region-beginning)
92 (region-end)) "")))
93 (when time
94 (kill-new (concat title " " time "\n\t" txt)) ;; hack: prepend to kill ring
95 (org-capture nil "E"))))
97 (provide 'org-exchange-capture)