[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

When the Split dialog in Figure 14-20 is submitted, all message parts are saved to the
directory you select, and known parts are automatically opened. Individual parts are
also automatically opened by the row of quick-access buttons labeled with the part’s
filename in the middle of the view window, after being saved to a temporary directory;
this is usually more convenient, especially when there are many attachments.


For instance, Figure 14-21 shows the two image parts attached to the mail we sent open
on my Windows laptop, in a standard image viewer on that platform; other platforms
may open this in a web browser instead. Click the image filenames’ quick-access but-
tons just below the message headers in Figure 14-18 to view them immediately, or run
Split to open all parts at once.


Figure 14-21. PyMailGUI opening image parts in a viewer or browser


By this point, the photo attachments displayed in Figure 14-21 have really gotten
around: they have been MIME encoded, attached, and sent, and then fetched, parsed,
and MIME decoded. Along the way, they have moved through multiple machines—
from the client, to the SMTP server, to the POP server, and back to the client, crossing
arbitrary distances along the way.


In terms of user interaction, we attached the images to the email in Figure 14-14 using
the dialog in Figure 14-15 before we sent the email. To access them later, we selected
the email for viewing in Figure 14-17 and clicked on their quick-access button in Fig-
ure 14-18. PyMailGUI encoded the photos in Base64 form, inserted them in the email’s
text, and later extracted and decoded it to get the original photos. With Python email
tools, and our own code that rides above them, this all just works as expected.


Notice how in Figures 14-18 and 14-19 the main message text counts as a mail part,
too—when selected, it opens in a PyEdit window, like that captured in Figure 14-22,


A PyMailGUI Demo| 1039
Free download pdf