IBM Power Systems AS/400 iSeries ¤Ë´Ø¤¹¤ë³Ð¤¨½ñ¤­¤Ê¥Ú¡¼¥¸¤Ç¤¹¡£

¥Ö¥é¥Ã¥¯¥Û¡¼¥ë¥á¡¼¥ë¥µ¡¼¥Ð¡¼

³µÍ×
Python¤Çµ­½Ò¤·¤¿¤Ò¤¿¤¹¤é¼õ¿®¤¹¤ë¤À¤±¥á¡¼¥ë¥µ¡¼¥Ð¡¼¤Ç¤¹¡£
·ë²Ì¤òSQLite3·Á¼°¤Î£Ä£Â¤Ë³ÊǼ¤·¤Þ¤¹¤Î¤Ç¡¢¼õ¿®·ë²Ì¤òÃΤꤿ¤¤»þ¤ÏSQLite3¤ò»È¤Ã¤ÆÃæ¿È¤òselect¤·¤Æ¤¯¤À¤µ¤¤¡£
»È¤¤Êý
Python SMTPSv.py [IP¥¢¥É¥ì¥¹] [¥Ý¡¼¥ÈÈÖ¹æ] [³ÊǼ¤¹¤ëDB̾]
Îã¡ËPython SMTPSv.py localhost 25 mail.db
# -*- coding: Shift-JIS -*-
import sys,sqlite3,asyncore,smtpd
from email import message_from_string
from email.Header import decode_header
from time import time

class MySMTPServer(smtpd.SMTPServer):
    def process_message(self, peer, mailfrom, rcpttos, data):
        msg = message_from_string(data)
        
        # ¥á¡¼¥ë¤òunicode¤Ë
        h = decode_header(msg.get('subject'))
        subject = ''
        for s, c in h:
            subject += unicode(s.decode(c)) + unicode(c)
        cset = msg.get_param('charset')
        b = msg.get_payload(decode=True)
        body = unicode(b.decode(cset)) + unicode(cset)
        to = decode_header(msg.get('to'))
        mailto = unicode(to)

        # SQLite¤Ë³ÊǼ
        connect = sqlite3.connect(sys.argv[3])
        connect.text_factory=str
        c = connect.cursor()
        c.execute("""CREATE TABLE IF NOT EXISTS mail (
            id INTEGER PRIMARY KEY,
            mailfrom TEXT,
            mailto TEXT,
            subject TEXT,
            body TEXT,
            maildate TEXT
            )""")
        c.execute('INSERT INTO mail VALUES (NULL,?,?,?,?,?)',(mailfrom,mailto,subject.encode('cp932'),body.encode('cp932'),msg['Date']))
        connect.commit()

if __name__ == '__main__':
    MySMTPServer((sys.argv[1], int(sys.argv[2])), None)
    asyncore.loop()

¤³¤Î¥Ú¡¼¥¸¤Ø¤Î¥³¥á¥ó¥È

dKyIQ0 Thanks so much for the article post. Great.

0
Posted by watch for this 2013ǯ12·î20Æü(¶â) 21:08:55 ÊÖ¿®

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

WikiÆ⸡º÷

Menu

¤³¤³¤Ï¼«Í³¤ËÊÔ½¸¤Ç¤­¤ë¥¨¥ê¥¢¤Ç¤¹¡£

¥á¥ó¥Ð¡¼¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹