[MT]mail2entry(python版)を設定する。

| | コメント(0)

MovableType(MT)で、携帯やPCからメールで記事をエントリーできるようにするため、JO ITOさんのmail2entryをインストール・設定します。
mail2entryは、python2.2以降と、pythonのJapaneseCodecsをインストールすれば使用できます。

これがあると、携帯から撮った写真をすぐにエントリーできるようになるので、出先からメモがてら記事を書くことが出来て便利です。

参考サイト
http://joi.ito.com/jp/archives/2002/12/26/002656.html

Python2とJapaneseCodec

# cd /usr/ports/lang/python
# make
(上記で、筆者の環境ではpython2.4がインストールされました。)
# cd /usr/ports/japanese/pycodec
# make
(pythonのJapaneseCodecをインストールしました。)

mail2entry-2002-12-25.tar の中身を /var/spool/mail2entry 等へ適当に入れます。

COPYING README parsemsg.py settings.py
INSTALL mail2entry.py postentry.py

ここで、settings.pyは自分のblogにあわせて、中身を適時編集します。

settings.py

"""Profile settings"""

# username: The name of an existing user for your Movable Type weblog.
# You probably want to create an account separate from your
# principle weblog user.
username = "MTにログインするときのユーザ名"

# password: The password associated with the above username.
password = "MTにログインするときのパスワード"

# blogid: The id of your Movable Type weblog. You can determine this id
# by looking for the value in the "blog_id" CGI variable in the
# Movable Type configuration URLs.
blogid = 1
categoryid = 1
### blogid と categoryid は使用するMTのブログ設定で確認できます。

# publish: Boolean (either True or False) which forces the publication
# of the new weblog entry. If False, the new entry will be
# queued until it is manually published.
publish = True

# savelocal: Boolean (either True of False) which determines if the images
# are to be saved locally. If False, the image is uploaded to
# your weblog through the newMediaObject XML-RPC API.
savelocal = True

# url: Pointer to the XML-RPC interface for your weblog. There is no
# requirement that your weblog must reside on the same server
# as the images are stored.
uri = "http://ドメイン名/mt-xmlrpc.cgi"

# imagesdirpath: Path to where images will be stored. If _savelocal_ is
# True, this is an absolute path on the local server. If
# False, the path is relative to your weblog directory.
imagesdirpath = "/var/www/ill"
### 写真を貼付した際の、イメージ保存先です。

# imageurldir: URL pointing to the web location for the resulting images.
# If the images are on the same server as your weblog, you need
# only specify the path portion of the URL (protocol and host are
# unnecessary). If _savelocal_ is True, this variable is unused
# (the weblog determines the final location of the image).
#imageurldir = "/ill"

# template: Template for the resulting blog entry. You probably don't
# need to change this.
template = "%(caption)s\n" + \
"<div class=\"photo\">%(imagecontent)s</div>"

# imgtemplate: Template for a single image entry. This gets embedded
# within _template_ when creating the full entry. If multiple
# images are found within an email message, _imgtemplate_ will
# be used for each image. The concatenation of all _imgtemplate_
# are used within _template_.
imgtemplate = "<img src=\"%(imageurl)s\">"

# logfilepath: Log file containing details of any errors (Python exceptions)
# which occur. New errors are appended to the end of this file.
# It needs to be writable by whatever user runs the mail2entry
# script.
#logfilepath = "/tmp/log-tracebacks.log"
logfilepath = "/var/spool/mail2entry/log-tracebacks.log"



なお、我が家ではPostfix(sendmail互換)が動作しているので、fmlと同じようにaliasからincludeを利用して、mail2entryに内容を渡します。

/etc/aliases

# blog
mail2entry: :include:/var/spool/mail2entry/include


※newaliases (postalias)忘れずに…。
この場合は、 mail2entry@ドメイン名といったメールアドレスに送られると、そのメールの内容が投稿される仕組みになります。

/var/spool/mail2entry/include "| /usr/local/bin/python2.4 /var/spool/mail2entry/mail2entry.py /var/spool/mail2entry"

/usr/local/bin/python2.4 のところは インストールしたpythonのver等によって適時変更下さい。

あとは、aliasで指定したメールアドレスに、適当にメールを送ればエントリーされます。
(MTの設定で、記事投稿時に下書きになる場合、自分でエントリーを公開する必要があります。)


うまく動かない場合は、log-tracebacks.logを参考にするといいです。

/var/spool/mail2entry/log-tracebacks.log

--------------------------------------------------------
2005-06-22 14:09

Traceback (most recent call last):
File "/var/spool/mail2entry/mail2entry.py", line 22, in main
content = parsemsg.parse(sys.stdin)
File "/var/spool/mail2entry/parsemsg.py", line 64, in parse
title = " ".join([unicodify(decoded_subject, charset) \
File "/var/spool/mail2entry/parsemsg.py", line 124, in unicodify
result = unicode(string, "japanese.iso-2022-jp-ext")
LookupError: unknown encoding: japanese.iso-2022-jp-ext
--------------------------------------------------------

上記の場合、

LookupError: unknown encoding: japanese.iso-2022-jp

となっているので、大抵はpythonのJapaneseCodecがインストールされていない場合が殆どです。
(私もはまりました…。)

コメントする

IPv4 Exhaustion Counter

Amazon

おすすめPC周辺機器
Powered by Movable Type 4.29

このブログ記事について

このページは、kentiが2006年5月 4日 14:56に書いたブログ記事です。

ひとつ前のブログ記事は「やっとおわった・・・。」です。

次のブログ記事は「連休ですなぁ。」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。