Blujacker 7 Junior Poster in Training

Hello
I am trying to create my own email client. I have one problem. I cant parse data from email. I am using poplib -> received email looks like this:

('+OK Message follows (1562 bytes).', ['Reply-To: =?iso-8859-2?Q?Jakub=20Voj=E1=E8ek?= <jakohv@seznam.cz>', 'Received: from kubuvpocitac (r3ai164.net.upc.cz [213.220.226.164])', '\tby email-relay2.go.seznam.cz (Seznam SMTPD 1.0.36@12969) with ESMTP;', '\tWed, 16 Apr 2008 18:46:52 +0200 (CEST)  ', 'Message-Id: <004f01c89fe1$7b567220$6e7ba8c0@kubuvpocitac>', 'From: =?iso-8859-2?Q?Jakub=20Voj=E1=E8ek?= <jakohv@seznam.cz>', 'To: jakohv@seznam.cz', 'Subject: predemr', 'Date: Wed, 16 Apr 2008 18:46:52 +0200 (CEST)', 'Mime-Version: 1.0', 'Content-Type: multipart/alternative;', '\tboundary="----=_NextPart_000_004A_01C89FF2.3C51E080"', 'X-Priority: 3', 'X-Msmail-Priority: Normal', 'X-Mailer: Microsoft Outlook Express 6.00.2900.3138', 'X-Mimeole: Produced By Microsoft MimeOLE V6.00.2900.3198', 'X-Smtpd: 1.0.36@12969', 'X-Seznam-User: jakohv@seznam.cz', 'X-Qm-Mark: email-qm1<17546722>', 'X-Seznam-Ffp: 680759260', '', 'This is a multi-part message in MIME format.', '', '------=_NextPart_000_004A_01C89FF2.3C51E080', 'Content-Type: text/plain;', '\tcharset="iso-8859-2"', 'Content-Transfer-Encoding: quoted-printable', '', 'hhahsd', '------=_NextPart_000_004A_01C89FF2.3C51E080', 'Content-Type: text/html;', '\tcharset="iso-8859-2"', 'Content-Transfer-Encoding: quoted-printable', '', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">', '<HTML><HEAD>', '<META http-equiv=3DContent-Type content=3D"text/html; =', 'charset=3Diso-8859-2">', '<META content=3D"MSHTML 6.00.2900.3314" name=3DGENERATOR>', '<STYLE></STYLE>', '</HEAD>', '<BODY bgColor=3D#ffffff>', '<DIV><FONT face=3DArial size=3D2>hhahsd</FONT></DIV></BODY></HTML>', '', '------=_NextPart_000_004A_01C89FF2.3C51E080--'], 1562)

I standard python distribution is modull called "email". I tryied to parse data with email.parser, but i wasnt sucesfull. Here is my parser:

import re
from email.parser import*
m1="""('+OK Message follows (1562 bytes).', ['Reply-To: =?iso-8859-2?Q?Jakub=20Voj=E1=E8ek?= <jakohv@seznam.cz>', 'Received: from kubuvpocitac (r3ai164.net.upc.cz [213.220.226.164])', '\tby email-relay2.go.seznam.cz (Seznam SMTPD 1.0.36@12969) with ESMTP;', '\tWed, 16 Apr 2008 18:46:52 +0200 (CEST)  ', 'Message-Id: <004f01c89fe1$7b567220$6e7ba8c0@kubuvpocitac>', 'From: =?iso-8859-2?Q?Jakub=20Voj=E1=E8ek?= <jakohv@seznam.cz>', 'To: jakohv@seznam.cz', 'Subject: predemr', 'Date: Wed, 16 Apr 2008 18:46:52 +0200 (CEST)', 'Mime-Version: 1.0', 'Content-Type: multipart/alternative;', '\tboundary="----=_NextPart_000_004A_01C89FF2.3C51E080"', 'X-Priority: 3', 'X-Msmail-Priority: Normal', 'X-Mailer: Microsoft Outlook Express 6.00.2900.3138', 'X-Mimeole: Produced By Microsoft MimeOLE V6.00.2900.3198', 'X-Smtpd: 1.0.36@12969', 'X-Seznam-User: jakohv@seznam.cz', 'X-Qm-Mark: email-qm1<17546722>', 'X-Seznam-Ffp: 680759260', '', 'This is a multi-part message in MIME format.', '', '------=_NextPart_000_004A_01C89FF2.3C51E080', 'Content-Type: text/plain;', '\tcharset="iso-8859-2"', 'Content-Transfer-Encoding: quoted-printable', '', 'hhahsd', '------=_NextPart_000_004A_01C89FF2.3C51E080', 'Content-Type: text/html;', '\tcharset="iso-8859-2"', 'Content-Transfer-Encoding: quoted-printable', '', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">', '<HTML><HEAD>', '<META http-equiv=3DContent-Type content=3D"text/html; =', 'charset=3Diso-8859-2">', '<META content=3D"MSHTML 6.00.2900.3314" name=3DGENERATOR>', '<STYLE></STYLE>', '</HEAD>', '<BODY bgColor=3D#ffffff>', '<DIV><FONT face=3DArial size=3D2>hhahsd</FONT></DIV></BODY></HTML>', '', '------=_NextPart_000_004A_01C89FF2.3C51E080--'], 1562)"""
m2="""('+OK Message follows (1601 bytes).', ['Reply-To: =?iso-8859-2?Q?Jakub=20Voj=E1=E8ek?= <jakohv@seznam.cz>', 'Received: from kubuvpocitac (r3ai164.net.upc.cz [213.220.226.164])', '\tby email-relay2.go.seznam.cz (Seznam SMTPD 1.0.36@12969) with ESMTP;', '\tThu, 17 Apr 2008 17:10:38 +0200 (CEST)  ', 'Message-Id: <00ba01c8a09d$320e0b70$6e7ba8c0@kubuvpocitac>', 'From: =?iso-8859-2?Q?Jakub=20Voj=E1=E8ek?= <jakohv@seznam.cz>', 'To: jakohv@seznam.cz', 'Subject: predemr', 'Date: Thu, 17 Apr 2008 17:10:36 +0200 (CEST)', 'Mime-Version: 1.0', 'Content-Type: multipart/alternative;', '\tboundary="----=_NextPart_000_00B7_01C8A0AD.F44443C0"', 'X-Priority: 3', 'X-Msmail-Priority: Normal', 'X-Mailer: Microsoft Outlook Express 6.00.2900.3138', 'X-Mimeole: Produced By Microsoft MimeOLE V6.00.2900.3198', 'X-Smtpd: 1.0.36@12969', 'X-Seznam-User: jakohv@seznam.cz', 'X-Qm-Mark: email-qm1<17566836>', 'X-Seznam-Ffp: -1361842557', '', 'This is a multi-part message in MIME format.', '', '------=_NextPart_000_00B7_01C8A0AD.F44443C0',  'Content-Type: text/plain;', '\tcharset="iso-8859-2"', 'Content-Transfer-Encoding: quoted-printable', '', "'sdfdf','sdf'", '------=_NextPart_000_00B7_01C8A0AD. F44443C0', 'Content-Type: text/html;', '\tcharset="iso-8859-2"', 'Content-Transfer-Encoding: quoted-printable', '', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0  Transitional//EN">', '<HTML><HEAD>', '<META http-equiv=3DContent-Type content=3 D"text/html; =', 'charset=3Diso-8859-2">', '<META content=3D"MSHTML 6.00.2900.33 14" name=3DGENERATOR>', '<STYLE></STYLE>', '</HEAD>', '<BODY bgColor=3D#ffffff>' , '<DIV><FONT face=3DArial =', "size=3D2>'sdfdf','sdf'</FONT></DIV></BODY></HTML >", '', '------=_NextPart_000_00B7_01C8A0AD.F44443C0--'], 1601)"""
m1=re.search(r"[\w]*\['(?P<x>[\w\W]*)'\]", m1).group("x").replace("', '","\n")
m2=re.search(r"[\w]*\['(?P<x>[\w\W]*)'\]", m2).group("x").replace("', '","\n")
print Parser().parsestr(m1).get_payload()[0].get_payload()
print Parser().parsestr(m2).get_payload()[0].get_payload()

There are two mails. Parsing of first email (m1) is OK, but the second one (m2) does not work.
Where is error?

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.