« MTの3カラム化 | メイン | 画像の投稿(2) »
November 12, 2004
mail2entry
■mail2entry
当サーバー(Vine Linux)では「 mail2entry」 を使用して moblog を実現してみました。
「 mail2entry」を使うことによって、モバイル機器から簡単に記事の投稿などが実現できます。
「 mail2entry」 は、「physon」と言うプログラム言語で書かれていたので、動作させるまでに苦戦しました。
まず、Mail2Entry からソースをダウンロードします。
$ fetch http://www.gweep.net/~aron/mail2entry/mail2entry20030506.tar.gz
つぎに、python がインストールされているか確認します。バージョンは 2.2.2 以上である必要があります。
$ which python
/usr/local/bin/python
Python Unicode codecs for Japanese charsets をインストールしなくてはなりません。
これは JapaneseCodecs からダウンロードできます。
http://www.python.jp/Zope/download/JapaneseCodecsより
”JapaneseCodecs-1.4.10.tar.gz” をダウンロード
> tar zxvf JapaneseCodecs-1.4.10.tar.gz
> cd JapaneseCodecs-1.4.10
> su -m
# /usr/local/bin/python setup.py install
これで python の準備はOKです。
つづいて mail2entry 本体のインストールと設定です。ダウンロードしておいたファイルを展開します。
$ tar xvzf mail2entry20030506.tar.gz
mail2entry20030506/
mail2entry20030506/parsemsg.py
mail2entry20030506/COPYING
mail2entry20030506/INSTALL
mail2entry20030506/README
mail2entry20030506/mail2entry.py
mail2entry20030506/postentry.py
mail2entry20030506/postimage.py
mail2entry20030506/saveimage.py
mail2entry20030506/settings.py
このディレクトリはどこに置いてもよいのですが、私は MT 下においています。
$ mv mail2entry20030506 /$MT/plugins/mail2entry
/$MT/ は mt.cgi のあるディレクトリです。次に settings.py を書き換えます。
> cat 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 = "username"
# password: The password associated with the above username.
password = "password"
# 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
# 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 = False
# 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://YourDomain/~YourName/mt/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 = "images/moblog_images"
# 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 = "http://YourDomain/~YourName/mt/images/moblog_images"
# template: Template for the resulting blog entry. You probably don't
# need to change this.
template = "<div class=\"caption\">%(caption)s</div>\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 = "./log-tracebacks.log"
テストします。
$ cat file | python /path/to/mail2entry.py ./
file には適当な短いファイルを指定します。このファイルの内容が新しいエントリとしてテストに使われます。/path/to の部分は適宜読み替えてください。私の場合は /$MT/plugins/mail2entry/mail2entry.py になりますね。mail2entry.py の引数は mail2entry の置かれているディレクトリを指定します。私の場合は /$MT/plugins/mail2entry/ になりますが、今はこのディレクトリ内にいるということを仮定しているので、./ としています。
これでうまくいっていれば新しい blog に新しいエントリが作製されているはずです。何かうまくいっていない場合、logfilepath に指定したところにログができているのでそれを見て対処してください。
メールからデータを受け取り、スクリプトを起動してエントリを書き込むpostfixでの設定です。
aliases に :include: を使用して実現しています。:include: を使用せずに、直接 aliases 内にパイプでmail2entryに渡してもよいのですが、そうすると作製されるログなどの Owner がpostfixの実行ユーザになったりするので(設定によって異なります)、:include:をたたいています。
まず、実行するファイルを用意します。引き続き、/$MT/plugins/mail2entry/ 内にいるとして、
$ vi include
"| /usr/local/bin/python /$MT/plugins/mail2entry/mail2entry.py /$MT/plugins/mail2entry/"
とします。最初と最後の " (ダブルクオーテーション) および | (パイプ) も必要です。
次に、ファイルの所有者とモードを変えておきます。
postfix のデフォルトの設定では、aliases 内に :include: を含むことを禁止しているので、 $postfix/main.cf 内に
allow_mail_to_commands = alias,forward,include
を追加して postfix を再起動します。
aliases を有効にします。
# cd /etc
# vi aliases
mail2entry: :include:/$MT/plugins/mail2entry/include
以上の行を追加します。一番最初の mail2entry というのはメールアドレスになるので好きなものを指定してください。この場合 mail2entry@example.com というアドレスが追加されたことになります。編集後は必ず newaliases を実行します。
# newaliases
これで終了です。何かおかしい場合、ファイルのパーミッションや、/tmp/log-trackbacks.log /var/log/maillog の内容などを調べてみてください。
投稿者 hare : November 12, 2004 9:33 PM
トラックバック
このエントリーのトラックバックURL:
http://seoc.dyndns.org/cgi-bin/mt/mt-tb.cgi/87
このリストは、次のエントリーを参照しています: mail2entry:
» 職場のmyデスク from Mari's Home
個人の席がパーテーションで区切られてます。
結構お気に入りです〜
祝!! ... [続きを読む]
トラックバック時刻: November 14, 2004 12:58 AM
コメント
moblog使ってみました!!
素敵です。これからどんどんmoblogってみます。ありがとうございます。
投稿者 Mari : November 14, 2004 12:54 AM
ちわー、moblogについてのコメントでなくて申し訳ないのですが。。。。
blog、カワイイデザインに変えてくれてありがとう! いつか変えよう、と思いつつずーっと放っていました。写真も小さくなっている・・・。
すっごく嬉しいけど、怠け癖がつきそーなのが心配です。
ありがとうございました
投稿者 こりー : November 17, 2004 6:16 AM
こりーさん
次回の画像投稿は、小さい画像を期待してますよ~!!
※復習
当HPの「カテゴリ-」→「MovableType」→「画像の投稿」に、画像を小さくする投稿方法が書いてあります。
投稿者 hare : November 17, 2004 8:24 PM