メールの添付ファイルを削除して先頭 1KB だけを転送したい

えー、家族が PC メールを読んでくれないというのは世界共通の悩みでございます。うちでも「なるべく1日1回は受信するようにして」といつも言ってるんですが、平気で1週間忘れる人がいるわけですよ。どうも「パソコンを/メーラーを起動する」という作業が日常生活に組み込まれていない。しかたないので、プロバイダにメールが届いたら携帯に転送して知らせることにしました。
PC 宛に届いたメールを携帯に転送するとなると次のような処理が必要になります。

  • 添付ファイルは削除
  • 長い本文は先頭 n バイトだけ切り出す

このレベルの機能は procmail にも組み込まれてない → んじゃチョロっと Ruby でフィルタを書くか → プロバイダのメールサーバに TMail が入ってねぇ → えぇ〜自前で書くのぉ〜めんどくさぁ〜い → 先人の知恵があるはずだ →

ubiqun
http://remoteroom.dyndns.org/archive/mah.pobox.ne.jp/ubiqun/
earth.rb
http://fjts.org/~m/Soft/Ruby/earth.rb/
UnreadMail
http://codezine.jp/a/article/aid/130.aspx

→earth 採用。後発だし Ruby 製ならいじれる → J-PHONE って何だっぺ…… au に送るなら 'etc' にしとけばいいのか → 先頭 n バイトだけ切り出すには……分割サイズを n バイトにして最大分割数を 1 にすればいいのか → 改行や全角空白が無条件に消されちゃう……消さない方法がわからない → ま、改行なくても内容はわかるからいいか →

earth_setting.rb

=begin

setting.rb

 Setting file for earth.rb

=end

# E-mail address for cellar phone.
To = 'hogehoge@ezweb.ne.jp'

# E-mail address that return error mail.
ReturnPathAddress = 'fugafuga@example.com'

# Smtp server
SmtpServer = 'localhost'

# Smtp port
SmtpPort = 25

# Whether use Smtp authentication.
UseSmtpAuth = false

# Smtp authentication type. ('cram_md5' or 'plain')
SmtpAuthType = 'cram_md5'

# Smtp user with using smtp auth.
SmtpUser = 'user'

# Smtp passwd with using smtp auth.
SmtpPasswd = 'passwd'

# Name of career. ('J-PHONE' or 'ETC'...)
PhoneType = 'ETC'

# Countent that count mail byte
MailByteContent = "subject_byte + from_byte + 2"

# Method to getting mail. ('Local' or 'POP')
GetMailType = 'Local'

# POP settings.
#
# [type, server, user, passwd, number of port]
#
PopSettings = [
  ['APOP', 'server1','user1', 'passwd1'],
  ['POP', 'server2','user2','passwd2', 10110],
]

# Maximum mail header line of one mail.
MaxHeaderLineOfOneMail = 100

# Maximum mail body byte of one mail. It's a vague value.
MaxBodyByteOfOneMail = 1048576

# Maximum number analyzed e-mail address in mail header.
MaxAnalsysAddressNum = 100

# Whether to Spool mail.
UseSpool = true

# Max number of Spool mail.
SpoolNumberMax = 100

# From type (nil for mail of from address)
FromType = nil

# Whether add Subject.
UseSubject = true

# Subject format (@from, @subject, @mail_number, @count_number)
SubjectFormat = "sprintf(\"%s\", @subject)"

# Max byte of subject
SubjectMaxByte = 200

# Beginning part of the first mail
# (@from, @subject, @mail_number, @count_number)
FirstBodyHead = "sprintf(\"%s にメールが届きました。以下は抜粋です: \", @tocc)"

# Beginning part of the mail except the first
# (@from, @subject, @mail_number, @count_number)
NextBodyHead = nil

# Whether send header infomation.
SendHeaderInfo = false

# Whether send header infomation mail last.
HeaderInfoLastSend = false

# Written number of address in infomation mail and in log.
MaxInfoAddressNum = 3

# Subject for infomation mail.
# (@from, @subject, @tocc, @match, @mail_number)
InfoMailSubject = "sprintf(\"%d/%s\", @mail_number,@from)"

# (@from, @subject, @tocc, @match, @date, @mail_number)
InfoMailBody = "sprintf(\"From: %s\nSubject: %s\nTo: %s\nDate: %s\nMatch: %s\", @from, @subject, @tocc, @date, @match)"

# From address for infomation mail.
InfoMailFromAddress = ReturnPathAddress

# Whether change line feed.
ChangeLineFeed = false

# Line feed character.
LineFeedCharacter = " "

# Max size of divided mail.
DefaultCutMaxByte = 5000

# Max number of divided mail.
DefaultMaxNumber = 1

# Max size of divided mail for reget command.
DefaultRegetMaxByte = 5000

# Max number of divided mail for reget command.
DefaultRegetMaxNumber = -1

# Patten matching rule.
#
# [keyword type, keyword, max mail byte, number of mail to send,
#  max mail byte for reget, number of mail to send for reget],
#
#  keyword type
#       'all' or 'tocc' or 'default' or header name
#        header name is 'from', 'subject', 'to', 'received', 'message-id', ...
Rule = [
  ['subject', '^Returned mail:', 0, 0],
  ['from', 'MAILER-DAEMON', 0, 0],
  ['from', 'Postmaster', 0, 0],
  ['default', nil],
]

# Whether transfer a mail which was send
# from the mail address which did not include @.
SendNoAtMarkAddress = true

# Whether use cuting of database.
UseDB = true

# Max byte for database file.
DBMaxFileByte = 20480

# Whether cut line.
CutLine = true

# Line to cut without qualification.
# Danger!!!!!
CutLinePattern = [
  'wrote:$',
  'writes:$',
  '^[ ]*At ',
  '^[ ]*On ',
  '^[ ]*In message',
  '^[ ]*From:',
  '^[ ]*To:',
  '^[ ]*Cc:',
  '^[ ]*Date:',
  '^[ ]*Subject:',
  '^[ ]*Sent:',
  '^[ ]*Message-I[dD]:',
  '^Sun,',
  '^Mon,',
  '^Tue,',
  '^Wed,',
  '^Thu,',
  '^Fri,',
  '^Sat,',
  '^\.*[> ]+ *At ',
  '^\.*[> ]+ *On ',
  '^\.*[> ]+ *In message', 
  '^[ ]*[:|> ]+ *At ',
  '^[ ]*[:|> ]+ *On ',
  '^[ ]*[:|> ]+ *In message', 
  '^[ ]*[:|> ]+ *Message-I[dD]:', 
  '^[ ]*[:|> ]+ *Date:', 
  '^[ ]*[:|> ]+ *From:', 
  '^[ ]*[:|> ]+ *Subject:', 
]

# Whether special squeeze function.
UseSqueeze = true

# Squeeze character
SqueezeCharacter = "─│┌┐┘└├┬┤┴┼━┃┏┓┛┗┣┳┫┻╋┠┯┨┷┿┝┰┥┸╂/\〜‖|…‥‘’”()〔〕[]{}〈〉《》「」『』【】+−±×=÷≠<>≦≧∞∴♂♀°′″℃¥$¢£%#&*@§☆★○●◎◇◆□■△▲▽▼※〒→←↑↓〓∈⊆∋⊇⊂⊃∪∩∧∨¬⇒⇔∀∃∠⊥⌒∂∇≡≒≫√∽∝∵∫∬ʼn♯♭♪†‡¶◯!#\$%&'()=~|-^`{[+;:]*?_<,.\""

# Whether edit reply.
EditReplyLine = true

# Whether write reply of only one line.
WriteOneReplyLine = true

# Latency between things of mail and mail.
LatencyTime = 10

# Whether use control command
UseCtrlCmd = false

# Password for control command 
CtrlCmdPassword = 'XXX'

# Check pattern of From address's list for control command
CtrlCmdFromList = [To]

# Check pattern of To address for control command
CtrlCmdTo = ReturnPathAddress

# Check pattern of Received for control command 
CtrlCmdReceived = /.*\.ezweb\.ne\.jp.*/

# Check pattern of Message-ID for control comannd 
CtrlCmdMessageID = /\.ezweb\.ne\.jp>$/

# Pause character of subject
SubjectPause = ''

# From E-mail address for vicarious execution sending.
VicariousFrom = 'name@example.ne.jp'

# Subject for vicarious execution sending.
VicariousSubject = 'from cellar phone'

# Bcc for vicarious execution sending.
VicariousBcc = [To,'example@example.co.jp']

# Signature for vicarious execution sending.
VicariousSignature = '
---
from cellar phone'

# Whether to suspend.
UseSuspend = false

# Pattern to appoint on a holiday.
#  [ time_format, pattern ],
Holiday = [
  [ "%a", '(Sun|Sat)' ],
  [ "%m%d", '010[12]' ],
  [ "%m%d", '0211' ],
  [ "%m%d", '0429' ],
  [ "%m%d", '050[345]' ],
  [ "%m%d", '0720' ],
  [ "%m%d", '0915' ],
  [ "%m%d", '11[02]3' ],
  [ "%m%d", '12(23|30|31)' ],
]

# Weekday's suspend time.
WeekdaySuspendTime = [
  [ 0, 630 ],
]

# Holiday's suspend time.
HolidaySuspendTime = [
  [ 2330, 2359 ],
  [ 0, 1000 ],
]

# Rule of mail to forward in suspend
IgnoreSuspendRule = [
   ['from', 'hogehoge@ezweb\.ne\.jp'],
]

→ 動作確認 OK. 添付ファイルもちゃんと除去された → あ、まだ HTML メールを試してないや → 手元にあった適当な HTML メールを秀丸メールで転送 → ちょw MIME エンコードされた文字列がズラズラ送られてww → Gmail で「リッチテキスト形式」で書いて送信 → ちゃんと除去された → うーん、ま、いっか♪
ところで、この手のツールの開発が J-PHONE 時代で止まってるってことは、今はもっといい方法があるってことなんですかね? 最近の情報をご存じの方はお知らせください。