Skip to content
Browse files

Initial commit of public version.

  • Loading branch information...
0 parents commit b60196ed4adbec311050dd9013891c623eb74077 @thomas11 committed
Showing with 188 additions and 0 deletions.
  1. +16 −0 README
  2. +172 −0 wpmail.el
@@ -0,0 +1,16 @@
+* About
+wpmail is a helper to post to by e-mail from Emacs. See
+wpmail.el for more info.
+ - Decent configuration, use defvar and don't clutter global
+ namespace. Or customize.
+ - Validity checks before mailing? Might be overkill.
+ - Post from current buffer, infer title, possibly depending on mode.
+ - Done except honoring mode, and this should better be left to
+ users as it will vary wildly. I don't need it at all, actually.
+ - Tests, possibly using ert.el
+ <>
172 wpmail.el
@@ -0,0 +1,172 @@
+;;; wpmail.el --- Post to wordpress by e-mail
+;; Author: Thomas Kappler <>
+;; Created: 2009 June 21
+;; Keywords: wordpress, blog, blogging
+;; URL: <>
+;; Copyright (C) 2009 Thomas Kappler
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; GNU General Public License for more details.
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <>.
+;;; Commentary:
+;; A number of functions to make posting by e-mail to the
+;; blog hosting service <>
+;; easier. It might work with other wordpress installations, which I
+;; have not tried. For more information about posting to wordpress by
+;; e-mail see the support page
+;; <>.
+;; Start a new post, possibly from the region or the buffer, with
+;; wpmail-new-post, and send it with wpmail-send-post when you're
+;; done. See the documentation of these functions for details.
+;; You must customize the following variables before you can use it.
+(defconst wpmail-posts-dir "~/Documents/Blog/"
+ "The directory where you store your blog posts.
+New posts will be started in a new buffer visiting a file
+there. You don't need to save the files at all, however.")
+(defconst wpmail-post-email ""
+ "The e-mail address you got from to send posts to.")
+(defvar wpmail-categories '("Own Code", "Stuff", "Weekly Links", "Weekly Reading")
+ "A list of the categories you use for blog posts.
+When starting a new post, wpmail will ask you for the
+category. These will be available for tab completion. However,
+you can also give a category that is not in this list.")
+(defvar wpmail-default-tags "code,programming,testing"
+ "A list of post tags that will appear whenever you start a new post.")
+(defconst wpmail-category-is-also-tag t
+ "When starting a new post, shall its category also be one of its tags?")
+;; Some helpers that might go into a more general library.
+;; -------------------------------------------------------
+(defun trim (string)
+ "Remove leading and trailing whitespace from STRING.
+ (replace-regexp-in-string "\\(^[ \t]*\\|[ \t]*$\\)" "" string))
+(defun options-for-post-title ()
+ "Make a list of suggestions for a blog post title.
+The list contains at least the buffer name. It also contains
+some text around point, if it's not empty and not too long."
+ (defun sensible-option-p (str)
+ (and (stringp str)
+ (< (length str) 60)
+ (> (length (trim str)) 4)))
+ (let ((options (list (buffer-name))))
+ ;; Things at point
+ (dolist (thing-kind (list 'word 'line 'sentence))
+ (let ((option (thing-at-point thing-kind)))
+ (if (sensible-option-p option)
+ (add-to-list 'options (trim option)))))
+ options))
+(defun buffer-or-region ()
+ "Return the region if it exists, the whole buffer otherwise."
+ (if (use-region-p)
+ (buffer-substring (region-beginning) (region-end))
+ (buffer-substring (point-min) (point-max))))
+;; End helpers -------------------------------------------
+(defun wpmail-new-post (title category init-content)
+ "Start a new wordpress blog post.
+The post will have the title TITLE and be in category CATEGORY.
+A new buffer will be created, visiting the file TITLE.wordpress
+in wpmail-posts-dir. There is no need to save this file,
+however, it can be sent, with TITLE preserved, without being
+If the third argument INIT-CONTENT is non-nil, the new post
+buffer is filled with the region if it exists, and with the whole
+content of the current buffer otherwise.
+The new post buffer will contain a list of shortcodes, directives
+the wordpress software evaluates when it receives the post. They
+will be initialized to hopefully sensible values, but you should
+check them before sending. In particular, you might wish to
+change the post tags or the status. See
+<> for documentation
+about shortcodes."
+ (interactive (list
+ (read-string "Title: " nil nil (options-for-post-title) nil)
+ (completing-read "Category: " wpmail-categories)
+ current-prefix-arg))
+ (let ((content (if init-content (wpmail-buffer-or-region) nil)))
+ (wpmail-initialize-new-post title category content)))
+(defun initialize-new-post (title category content)
+ "Does the actual work after wpmail-new-post got the user's input."
+ (unless content (setq content ""))
+ (wpmail-create-and-show-new-post-buffer title category content)
+ (set-visited-file-name (concat wpmail-posts-dir "/" title ".wordpress"))
+ (make-local-variable 'wpmail-post-title)
+ (setq wpmail-post-title title))
+(defun create-and-show-new-post-buffer (title category content)
+ "Create a new buffer named TITLE and initialize it."
+ (let ((post-buffer (get-buffer-create title)))
+ (set-buffer post-buffer)
+ (goto-char (point-max))
+ (insert "\n")
+ (insert content)
+ (insert (wpmail-initial-shortcodes category wpmail-default-tags))
+ (goto-char (point-min))
+ (switch-to-buffer post-buffer)))
+(defun initial-shortcodes (category tags)
+ "Return the wordpress shortcodes as a string; see wpmail-new-post."
+ (mapconcat 'identity
+ (list
+ "\n"
+ (concat "[category " category "]")
+ (concat "[tags " tags
+ (if wpmail-category-is-also-tag (concat "," category) "")
+ "]")
+ "[status draft]"
+ "-- "
+ "Anything after the signature line \"-- \" will not appear in the post."
+ "Status can be publish, pending, or draft."
+ "[slug some-url-name]"
+ "[excerpt]some excerpt[/excerpt]"
+ "[delay +1 hour]"
+ "[comments on | off]"
+ "[password secret-password]")
+ "\n"))
+(defun wpmail-send-post ()
+ "Send the post to by e-mail.
+Partly copied from Trey Jackson
+ (interactive)
+ (let ((content (buffer-substring-no-properties (point-min) (point-max))))
+ (message-mail wpmail-post-email wpmail-post-title)
+ (message-goto-body)
+ (insert content)
+ (message-send-and-exit)))
+(provide 'wpmail)

0 comments on commit b60196e

Please sign in to comment.
Something went wrong with that request. Please try again.