In both synchronization error cases, the mail list is automatically reloaded with the new
inbox content by PyMailGUI immediately after the error pop up is dismissed. This
scheme ensures that PyMailGUI won’t delete or display the wrong message, in the rare
case that the server’s inbox is changed without its knowledge. See mailtools in Chap-
ter 13 for more on synchronization tests; these errors are detected and raised in mail
tools, but triggered by calls made in the mail cache manager here.
Handling HTML Content in Email
Up to this point, we’ve seen PyMailGUI’s basic operation in the context of plain-text
emails. We’ve also seen it handling HTML part attachments, but not the main text of
HTML messages. Today, of course, HTML is common for mail content too. Because
the PyEdit mail display deployed by PyMailGUI uses a tkinter Text widget oriented
toward plain text, HTML content is handled specially:
- For text/HTML alternative mails, PyMailGUI displays the plain text part in its view
window and includes a button for opening the HTML rendition in a web browser
on demand. - For HTML-only mails, the main text area shows plain text extracted from the
HTML by a simple parser (not the raw HTML), and the HTML is also displayed
in a web browser automatically.
In all cases, the web browser’s display of International character set content in the
HTML depends upon encoding information in tags in the HTML, guesses, or user
feedback. Well-formed HTML parts already have “” tags in their “
sections which give the HTML’s encoding, but they may be absent or incorrect. We’ll
learn more about Internationalization support in the next section.
Figure 14-38 gives the scene when a text/HTML alternative mail is viewed, and Fig-
ure 14-39 shows what happens when an HTML-only email is viewed. The web browser
in Figure 14-38 was opened by clicking the HTML part’s button; this is no different
than the HTML attachment example we saw earlier.
For HTML-only messages, though, behavior is new here: the view window on the left
in Figure 14-39 reflects the results of extracting plain text from the HTML shown in
the popped-up web browser behind it. The HTML parser used for this is something of
a first-cut prototype, but any result it can give is an improvement on displaying raw
HTML in the view window for HTML-only mails. For simpler HTML mails of the sort
sent by individuals instead of those sent by mass-mailing companies (like those shown
here), the results are generally good in tests run to date, though time will tell how this
prototype parser fares in today’s unforgiving HTML jungle of nonstandard and non-
conforming code—improve as desired.
A PyMailGUI Demo| 1053