email-eww

Emacs library to send region or eww buffer by email
git clone https://logand.com/git/email-eww.git/
Log | Files | Refs

email-eww.el (3881B)


      1 ;;; email-eww.el
      2 ;;;
      3 ;;; Emacs library to send region or eww buffer by email.
      4 ;;;
      5 ;;; Author: Tomas Hlavaty <tom at logand dot com>
      6 ;;;
      7 ;;; License: GPL v3 or later
      8 ;;;
      9 ;;; Inspired by
     10 ;;; http://kitchingroup.cheme.cmu.edu/blog/2014/06/08/Better-integration-of-org-mode-and-email/
     11 
     12 (defcustom email-eww-to
     13   ""
     14   "Recipient email address."
     15   :group 'email-eww
     16   :type 'string)
     17 
     18 (defun email-region (start end)
     19   "Send region as the body of an email."
     20   (interactive "r")
     21   (let ((content (buffer-substring start end))
     22         (title (or (plist-get eww-data :title)
     23                    (buffer-name (current-buffer))))
     24         (url (plist-get eww-data :url)))
     25     (compose-mail email-eww-to title)
     26     (message-goto-body)
     27     (when url
     28       (insert url)
     29       (insert "\n\n"))
     30     (insert content)
     31     (message-goto-to)))
     32 
     33 (defun clean-up-ycombinator ()
     34   (next-line)
     35   (kill-line 2)
     36   (cond
     37    ((search-forward "Ask HN" nil t)
     38     )
     39    ((search-forward "comment" nil t)
     40     (beginning-of-line))
     41    )
     42   (let ((start (point)))
     43     (cond
     44      ((search-forward "add comment" nil t)
     45       (beginning-of-line)
     46       (next-line)
     47       (delete-region start (point)))
     48      ))
     49   (goto-char (point-max))
     50   (search-backward "reply")
     51   (next-line)
     52   (delete-region (point) (point-max))
     53   (message-goto-body)
     54   (unless (bolp)
     55     (forward-line 1))
     56   (delete-whitespace-rectangle (point) (point-max) nil)
     57   (message-goto-body)
     58   (flush-lines "^reply$" (point) (point-max)))
     59 
     60 (defun clean-up-reddit ()
     61   (next-line 2)
     62   (let ((start (point)))
     63     (cond
     64      ((search-forward "Posted by" nil t)
     65       (beginning-of-line)
     66       (next-line)
     67       (delete-region start (point)))
     68      ((search-forward-regexp "^submitted" nil t)
     69       (beginning-of-line)
     70       (previous-line)
     71       (backward-paragraph)
     72       (delete-region start (point)))
     73      ))
     74   (goto-char (point-max))
     75   (or (search-backward "Community Details" nil t)
     76       (search-backward "* reply"))
     77   (beginning-of-line)
     78   (delete-region (point) (point-max))
     79   (message-goto-body)
     80   (flush-lines "^share$" (point) (point-max))
     81   (flush-lines "^save$" (point) (point-max))
     82   (flush-lines "^hide$" (point) (point-max))
     83   (flush-lines "^report$" (point) (point-max))
     84   (flush-lines "^search$" (point) (point-max))
     85   (flush-lines "^Reply$" (point) (point-max))
     86   (flush-lines "^reportSave$" (point) (point-max))
     87   (flush-lines "^Sort by$" (point) (point-max))
     88   (flush-lines "^best$" (point) (point-max))
     89   (flush-lines "^besttopnewcontroversialoldq&a$" (point) (point-max))
     90   (flush-lines "^* permalink$" (point) (point-max))
     91   (flush-lines "^* embed$" (point) (point-max))
     92   (flush-lines "^* save$" (point) (point-max))
     93   (flush-lines "^* parent$" (point) (point-max))
     94   (flush-lines "^* report$" (point) (point-max))
     95   (flush-lines "^* give gold$" (point) (point-max))
     96   (flush-lines "^* share$" (point) (point-max))
     97   (flush-lines "^Post a comment!$" (point) (point-max))
     98   (flush-lines "^Create an account$" (point) (point-max))
     99   (flush-lines "^* reply$" (point) (point-max))
    100   (flush-lines "^*$" (point) (point-max))
    101   ;;(delete-blank-lines)
    102   (while (search-forward-regexp "\\(^\\s-*$\\)\n" nil t)
    103     (replace-match "\n")
    104     (unless (= (point) (point-max))
    105       (forward-char 1))))
    106 
    107 (defun email-eww ()
    108   (interactive)
    109   (let ((content (buffer-string))
    110         (title (or (plist-get eww-data :title)
    111                    (buffer-name (current-buffer))))
    112         (url (plist-get eww-data :url)))
    113     (compose-mail email-eww-to title)
    114     (message-goto-body)
    115     (when url
    116       (insert url)
    117       (insert "\n\n"))
    118     (insert content)
    119     (message-goto-body)
    120     (delete-trailing-whitespace)
    121     (cond
    122      ((search "news.ycombinator.com" url)
    123       (clean-up-ycombinator))
    124      ((search "reddit.com" url)
    125       (clean-up-reddit))
    126      )
    127     (goto-char (point-max))
    128     (delete-blank-lines)
    129     (message-goto-to)))
    130 
    131 (provide 'email-eww)