Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

14.5 | Processing a Linux Mailbox

To process a Linux-style mailbox into individual messages, a different control structure is required. Note, however, that the processing of each individual e-mail is handled by ProcessMessage, which is common to both Linux and Eudora converters.

CD-ROM reference=14006.txt
DoLinuxMailBox(f):
      # f is a file object.
      L = f.readline()[:-1]
      if string.find(L,"From ")!=0:
            -print 'Expected mailbox "%s" to start with "From "' % MailBox
            return
      Message = []
      L = f.readline()
      while L:
            if string.find(L,"From ")==0:
                  -# Full message accumulated in the Message  # list, so process it to XML
                  ProcessMessage(Message,out)
                  Message = []
            else:
                  # Accumulate e-mail contents line by line in
                  # Message list.
                  Message.append (L)
            L = f.readline()
      if Message:
            # Last message in the mailbox
            ProcessMessage(Message,out)
  • + Share This
  • 🔖 Save To Your Account