org-exchange-capture.el 3.5 KB

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