[Comm] òÁÓÓÙÌËÁ ÐÏÞÔÙ

Alexey Morsov =?iso-8859-1?q?samurai_=CE=C1_ricom=2Eru?=
ðÔ éÀÌ 4 10:39:36 MSD 2008


On Thu, Jul 03, 2008 at 06:38:20PM +0400, Ilya Raskin wrote:
> � можно погл�деть на �то чудо?
> � то в�е что вроде по функционально�ти 
> подходит - дл� выньды. а sympa �обирать�� 
> отказала�ь. :(
Приатачил.
�дре�а до�тают�� из MySQl, но вам никто не машет или до�тавать их из
тек�тового файла или таки загнать их �к�ел� в БД :)

-- 
WBR,
Alexey Morsov
программи�т З�О "ИК "Риком-Тра�т"
Jabber: samurai ÎÁ www.fondmarket.ru
ALT Linux Team Member

Переход пактов из рук в руки вызывает дрейф багов.
		-- at in devel@
----------- �ледующа� ча�ть -----------
#!/usr/bin/python
#-*- mode: python; coding: koi8-r -*-

import sys, os
from StringIO import StringIO
import os
import MySQLdb
from string import split, lstrip, rstrip
from email import *
import smtplib



def emailing(list_id, text, filename=None, attach=None, filetype=None):
	msg = MIMEMultipart.MIMEMultipart()

	db = MySQLdb.connect(host='', db='', user='', passwd='')

	msg['Subject'] = Header.Header("ôÅÍÁ ÐÉÓØÍÁ","koi8-r").encode()
	    
	msg['From'] = Utils.formataddr((Header.Header("÷ÁÛÁ ÌÀÂÑÝÁÑ ËÏÍÐÁÎÉÑ","koi8-r").encode(),
		'postmaster ÎÁ yourdomain.com'))

	message = StringIO()

	message.write(text)
	txt = MIMEText.MIMEText(message.getvalue(),'plain','koi8-r')
	message.close()
	msg.attach(txt)

	if filename:
		doc = MIMEBase.MIMEBase('application',filetype)
		doc.set_payload(attach)
		Encoders.encode_base64(doc)
		doc.add_header('Content-Disposition', 'attachment', filename=filename)
		msg.attach(doc)

	# cycle through the emails of subscribers
	cur.execute("select email from youremaildtable")
	for line in cur.fetchall():
		try:
			msg.replace_header('To',Utils.formataddr(('',line[0])))
		except KeyError:
			msg['To'] = Utils.formataddr(('',line[0]))
		s = smtplib.SMTP()
		s.connect()
		try:
			s.sendmail('postmaster ÎÁ yourdomain.com', line[0], msg.as_string())
		except smtplib.SMTPRecipientsRefused, msg:
			s.sendmail('postmaster ÎÁ yourdomain.com', 'postmaster ÎÁ yourdomain.com', 
					"To: <postmaster ÎÁ yourdomain.com>\nSubject: Maillist send error\n\n%s"%(msg))
		s.close()

	cur.close()
	db.close()




def main():
	buf = StringIO()

	map(buf.write,sys.stdin)
	msg = message_from_string(buf.getvalue())
	buf.close()

	print rstrip(lstrip(split(msg.get('Return-Path'))[-1],'<'),'>')
	if rstrip(lstrip(split(msg.get('Return-Path'))[-1],'<'),'>') == 'postmaster ÎÁ yourdomain.com':
		subj = Header.decode_header(msg.get('Subject'))[0][0]
		for part in msg.walk():
			if part.get_content_type() == 'text/plain':
				text = part.get_payload(decode=1)
				filetype = 'text'
			if part.get_content_type() == 'application/msword':
				filename = Header.decode_header(part.get_filename())[0][0]
				attach = part.get_payload(decode=1)
				filetype = 'word'
			if part.get_content_type() == 'application/pdf':
				filename = Header.decode_header(part.get_filename())[0][0]
				attach = part.get_payload(decode=1)
				filetype = 'pdf'
			else:
				filename = None
				attach = None
				filetype = None
		emailing(subj,text,filename,attach,filetype)


if __name__ == '__main__':
	main()

----------- �ледующа� ча�ть -----------
Было удалено вложение не в тек�товом формате...
Им�     : =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Тип     : application/pgp-signature
Размер  : 489 байтов
Опи�ание: Digital signature
Url     : <http://lists.altlinux.org/pipermail/community/attachments/20080704/e9516d70/attachment-0002.bin>


ðÏÄÒÏÂÎÁÑ ÉÎÆÏÒÍÁÃÉÑ Ï ÓÐÉÓËÅ ÒÁÓÓÙÌËÉ community