diff --context mail2entry-2003-05-01/mail2entry.py mail2entry-2003-03-10/mail2entry.py *** mail2entry-2003-05-01/mail2entry.py Thu May 1 13:22:17 2003 --- mail2entry-2003-03-10/mail2entry.py Mon Mar 10 11:32:02 2003 *************** *** 17,29 **** import saveimage content, images = parsemsg.parse(sys.stdin) ! if not(images == []): ! imageurls = saveimage.save ( images ) ! imagecontent = map ( lambda imageurl : imgtemplate % \ { 'imageurl' : imageurl }, imageurls ) - else: - imagecontent = u'' entry = template % { 'caption' : content['description'], 'imagecontent' : "\n".join(imagecontent) } --- 17,26 ---- import saveimage content, images = parsemsg.parse(sys.stdin) + imageurls = saveimage.save ( images ) ! imagecontent = map ( lambda imageurl : imgtemplate % \ { 'imageurl' : imageurl }, imageurls ) entry = template % { 'caption' : content['description'], 'imagecontent' : "\n".join(imagecontent) } diff --context mail2entry-2003-05-01/parsemsg.py mail2entry-2003-03-10/parsemsg.py *** mail2entry-2003-05-01/parsemsg.py Thu May 1 13:22:18 2003 --- mail2entry-2003-03-10/parsemsg.py Tue Mar 11 10:01:59 2003 *************** *** 8,15 **** from email import * from email.Header import * - from japanese import * - import re class ParseMsgError(Exception): pass --- 8,13 ---- *************** *** 35,93 **** content = {'title': title} images = [] - content['description'] = u'' if msg.is_multipart(): parts = msg.get_payload() num_parts = len(parts) ! if num_parts >= 1: ! for each_part in parts[0:] : ! if (re.match("^text$", each_part.get_content_maintype(), \ re.IGNORECASE)): ! content['description'] += parse_text_part(each_part) ! else: ! if each_part.is_multipart(): ! each_parts = each_part.get_payload() ! for each_each_part in each_parts[0:] : ! imageinfo = parse_image_part(each_each_part) ! if (imageinfo): ! images.append(imageinfo) ! else: ! imageinfo = parse_image_part(each_part) ! if (imageinfo): ! images.append(imageinfo) else: raise UnexpectedNumOfMIMEParts else: ! if (re.match("^text$", msg.get_content_maintype(), \ ! re.IGNORECASE)): ! content['description'] = parse_text_part(msg); ! else: ! imageinfo = parse_image_part(msg) ! if (imageinfo): ! images.append(imageinfo) ! ! return content, images ! ! def parse_image_part(msg_part): ! try: ! imageinfo = handle_image_portion(msg_part) ! except SecondMIMEPartNotImage: ! imageinfo = False ! else: ! pass ! return imageinfo; ! def parse_text_part(msg_part): ! msg_charset = msg_part.get_param("charset") ! body = msg_part.get_payload(decode=1) ! # drop first line if it begins w/ cell phone number (11 digits) ! body = re.sub("^\d{11}[^\n]*\n", "", body) ! ! body = unicodify(body, msg_charset) ! return body; def handle_image_portion(msg_part): """""" --- 33,74 ---- content = {'title': title} images = [] if msg.is_multipart(): parts = msg.get_payload() num_parts = len(parts) ! if num_parts >= 2: ! first_part = parts[0] ! ! if not(re.match("^text$", first_part.get_content_maintype(), \ re.IGNORECASE)): ! raise FirstMIMEPartNotText ! ! # XXX: bug in email.Message.get_charset()? ! # first_charset = first_part.get_charset() ! first_charset = first_part.get_param("charset") ! body = first_part.get_payload(decode=1) ! ! # drop first line if it begins w/ cell phone number (11 digits) ! body = re.sub("^\d{11}[^\n]*\n", "", body) ! ! body = unicodify(body, first_charset) ! ! content['description'] = body ! ! for each_part in parts[1:] : ! imageinfo = handle_image_portion(each_part) ! images.append(imageinfo) else: raise UnexpectedNumOfMIMEParts else: ! content['description'] = u'' ! imageinfo = handle_image_portion(msg) ! images.append(imageinfo) ! return content, images def handle_image_portion(msg_part): """"""