Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Recursively Descend MIME Message Structure
Python script demonstrating how to recursively descend through the nesting of a MIME message. A complex MIME message is created by first downloading and converting a web page into an email, then adding a plain-text alternative body, then adding file attachments, and finally accessing the email as a MIME object to be examined. # file: mimeTraverse.py # -*- coding: windows-1252 -*- # (Python MIME parsing and building example script.) import chilkat def traverseMime(mime, level): line = "" for i in range(level): line = line + "----" line = line + mime.contentType() print line n = mime.get_NumParts() for i in range(n): part = mime.GetPart(i) traverseMime(part,level+1) # This example builds a complex email: # -- one that has both plain-text and HTML alternative bodies. # -- the HTML has embedded images # -- there are multiple attachments. # We then examine the MIME structure using Chilkat MIME. # First, we'll need the email component unlocked... mailman = chilkat.CkMailMan() mailman.UnlockComponent("anything for 30-day trial") # We'll convert a web page into an email with embedded # images. mht = chilkat.CkMht() mht.UnlockComponent("anything for 30-day trial") # Our URL was picked at random... email = mht.GetEmail("http://www.masukolandscaping.com/") # Add a plain-text alternative body. email.AddPlainTextAlternativeBody("this is the plain-text alternative...") # Add a few file attachments: strContentType = chilkat.CkString() # AddFileAttachment returns the auto-selected content-type in strContentType email.AddFileAttachment("images/dudePython.gif",strContentType) email.AddFileAttachment("blah.txt",strContentType) # Now we have a complex email. Get it as a MIME object and examine # the structure... mime = chilkat.CkMime() mime.UnlockComponent("anything for 30-day trial") mime = email.GetMimeObject(); mime.SaveMime("e.eml") traverseMime(mime,0) # Prints this: # multipart/mixed # ----multipart/related # --------multipart/alternative # ------------text/plain # ------------text/html # --------image/gif # --------image/gif # --------image/gif # --------image/gif # --------image/gif # --------image/gif # --------image/jpeg # --------image/gif # --------image/gif # --------image/gif # --------image/gif # --------image/gif # ----image/gif # ----text/plain |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.