email-eww

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

commit 8f47e9b24024c60707f04475773bb8c0a34c4fcd
parent 9e564f245608ad02d2af5a06f5c5bf2b249e1e6d
Author: Tomas Hlavaty <tom@logand.com>
Date:   Thu, 26 Sep 2019 07:03:03 +0200

content

Diffstat:
Aemail-eww.el | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 131 insertions(+), 0 deletions(-)

diff --git a/email-eww.el b/email-eww.el @@ -0,0 +1,131 @@ +;;; email-eww.el +;;; +;;; Emacs library to send region or eww buffer by email. +;;; +;;; Author: Tomas Hlavaty <tom at logand dot com> +;;; +;;; License: GPL v3 or later +;;; +;;; Inspired by +;;; http://kitchingroup.cheme.cmu.edu/blog/2014/06/08/Better-integration-of-org-mode-and-email/ + +(defcustom email-eww-to + "" + "Recipient email address." + :group 'email-eww + :type 'string) + +(defun email-region (start end) + "Send region as the body of an email." + (interactive "r") + (let ((content (buffer-substring start end)) + (title (or (plist-get eww-data :title) + (buffer-name (current-buffer)))) + (url (plist-get eww-data :url))) + (compose-mail email-eww-to title) + (message-goto-body) + (when url + (insert url) + (insert "\n\n")) + (insert content) + (message-goto-to))) + +(defun clean-up-ycombinator () + (next-line) + (kill-line 2) + (cond + ((search-forward "Ask HN" nil t) + ) + ((search-forward "comment" nil t) + (beginning-of-line)) + ) + (let ((start (point))) + (cond + ((search-forward "add comment" nil t) + (beginning-of-line) + (next-line) + (delete-region start (point))) + )) + (goto-char (point-max)) + (search-backward "reply") + (next-line) + (delete-region (point) (point-max)) + (message-goto-body) + (unless (bolp) + (forward-line 1)) + (delete-whitespace-rectangle (point) (point-max) nil) + (message-goto-body) + (flush-lines "^reply$" (point) (point-max))) + +(defun clean-up-reddit () + (next-line 2) + (let ((start (point))) + (cond + ((search-forward "Posted by" nil t) + (beginning-of-line) + (next-line) + (delete-region start (point))) + ((search-forward-regexp "^submitted" nil t) + (beginning-of-line) + (previous-line) + (backward-paragraph) + (delete-region start (point))) + )) + (goto-char (point-max)) + (or (search-backward "Community Details" nil t) + (search-backward "* reply")) + (beginning-of-line) + (delete-region (point) (point-max)) + (message-goto-body) + (flush-lines "^share$" (point) (point-max)) + (flush-lines "^save$" (point) (point-max)) + (flush-lines "^hide$" (point) (point-max)) + (flush-lines "^report$" (point) (point-max)) + (flush-lines "^search$" (point) (point-max)) + (flush-lines "^Reply$" (point) (point-max)) + (flush-lines "^reportSave$" (point) (point-max)) + (flush-lines "^Sort by$" (point) (point-max)) + (flush-lines "^best$" (point) (point-max)) + (flush-lines "^besttopnewcontroversialoldq&a$" (point) (point-max)) + (flush-lines "^* permalink$" (point) (point-max)) + (flush-lines "^* embed$" (point) (point-max)) + (flush-lines "^* save$" (point) (point-max)) + (flush-lines "^* parent$" (point) (point-max)) + (flush-lines "^* report$" (point) (point-max)) + (flush-lines "^* give gold$" (point) (point-max)) + (flush-lines "^* share$" (point) (point-max)) + (flush-lines "^Post a comment!$" (point) (point-max)) + (flush-lines "^Create an account$" (point) (point-max)) + (flush-lines "^* reply$" (point) (point-max)) + (flush-lines "^*$" (point) (point-max)) + ;;(delete-blank-lines) + (while (search-forward-regexp "\\(^\\s-*$\\)\n" nil t) + (replace-match "\n") + (unless (= (point) (point-max)) + (forward-char 1)))) + +(defun email-eww () + (interactive) + (let ((content (buffer-string)) + (title (or (plist-get eww-data :title) + (buffer-name (current-buffer)))) + (url (plist-get eww-data :url))) + (compose-mail email-eww-to title) + (message-goto-body) + (when url + (insert url) + (insert "\n\n")) + (insert content) + (message-goto-body) + (delete-trailing-whitespace) + (cond + ((search "news.ycombinator.com" url) + (clean-up-ycombinator)) + ((search "reddit.com" url) + (clean-up-reddit)) + ) + (goto-char (point-max)) + (delete-blank-lines) + (message-goto-to))) + +(provide 'email-eww)