[Tutor] MIME from string?

Ertl, John John.Ertl at fnmoc.navy.mil
Fri Mar 19 12:47:28 EST 2004


I am just starting to investigate MIME and how to use it in a web service to
send images using ZSI SOAP.  I have been trying to take a multipart mime
message and read it in and parse it.  The message is from a ZSI test (that
uses mimetools...now depricated).  I have done the following:

def parsseMessage(mime):
            msgstring = mime
            msg = email.message_from_string(msgstring)
            print msg.is_multipart()
            print msg.get_content_maintype()
            for part in msg.walk():
               print part.get_content_type()

The output is:
False
text
text/plain

How do I read in a MIME message from a string and have it recognize that it
is a multipart message.

mime = """
Return-Path: <rsalz at zolera.com>
Received: from zolera.com (os390.zolera.com [10.0.1.9])
        by zolera.com (8.11.0/8.11.0) with ESMTP id f57I2sf00832
        for <rsalz at zolera.com>; Thu, 7 Jun 2001 14:02:54 -0400
Sender: rsalz at zolera.com
Message-ID: <3B1FC1D1.FF6B21B4 at zolera.com>
Date: Thu, 07 Jun 2001 14:02:57 -0400
From: Rich Salz <rsalz at zolera.com>
X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i686)
X-Accept-Language: en
MIME-Version: 1.0
To: rsalz at zolera.com
Subject: mime with attachments
Content-Type: multipart/mixed;
 boundary="------------68E4BAC5B266315E42428C64"
Status: R

This is a multi-part message in MIME format.
--------------68E4BAC5B266315E42428C64
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

<SOAP-ENV:Envelope
 xmlns="http://www.example.com/schemas/TEST"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:ZSI="http://www.zolera.com/schemas/ZSI/">
<SOAP-ENV:Body>
<hreftest>
    <stringtest href="cid:part1 at zolera.com"/>
    <b64 href="cid:partii at zolera.com"/>
    <xmltest href="cid:12 at zolera.com"/>
</hreftest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--------------68E4BAC5B266315E42428C64
Content-Type: text/plain; charset=us-ascii;
 name="abs.txt"
Content-Transfer-Encoding: 7bit
Content-ID: <part1 at zolera.com>
Content-Disposition: inline;
 filename="abs.txt"


Digitial Signatures in a Web Services World

An influential Forrestor report created the term inverted security: it's
not about who you keep out, it's about who you let in.  Customer portals,
without a costly PKI deployment or application integration issues.

--------------68E4BAC5B266315E42428C64
Content-Type: application/pdf;
 name="gmpharma.pdf"
Content-Transfer-Encoding: base64
Content-ID: <partii at zolera.com>
Content-Disposition: inline;
 filename="gmpharma.pdf"

JVBERi0xLjINJeLjz9MNCjQzIDAgb2JqDTw8IA0vTGluZWFyaXplZCAxIA0vTyA0NSANL0gg
WyAxMTQ0IDM5NiBdIA0vTCA2NjkwMiANL0UgMTAyODIgDS9OIDkgDS9UIDY1OTI0IA0+PiAN
RB3nwVOQH9JpmFv6Ri2Zq7mlddSS2B5WcZwvAP+gy9QtuYlfqj1rsi9WqJOszzHXmXZ8fXxK
XBBztIpgbkRrd+SGtY4QXo0fX0VN86uKXwtrkd7h1qiq2FUtXl6uNfnCoyX1Dve1O3RPRyhG
sKn6fLMb+uSSIHPQkClRBwu5gechz/1PBUBSB34jXbPdMTIb+/wRP+pauSAhLBzFELDOgk5b
PaIPAnIudFovQTc7Df2Ws9Atz4Bua+oINphIOojogG5LP3Tb3oNu8bsmuK+wFXEdbfgFIx+G
gKULYx5A2WnaDXB5JeoRQg90S0HcX2dCPmRCqDXB/aX34KujsPwJ/UpRdxXPeAftDkQS6hag
bh/yTOiUyqBz9CzxnyMYQGDO0jrUZ47kkWfmYvVg
--------------68E4BAC5B266315E42428C64
Content-ID: <12 at zolera.com>

<foo xmlns="example.com" xmlns:Z="zolera">
    this is a foo
    <b xmlns:Z="zolera">redundnant ns decl</b>
    <b Z:x="this was first" Z:a="2nd-orig">b test</b>
</foo>

--------------68E4BAC5B266315E42428C64--
"""

John C. Ertl
Fleet Numerical Meteorology & Oceanography Center
7 Grace Hopper Ave
Monterey, CA 93943
phone: (831) 656-5704
fax:   (831) 656-4363




More information about the Tutor mailing list