Version 1 of Reading messages that might be MIME-encoded

Updated 2002-01-31 23:27:36

[...]

[Explain environment.]

[Code recursion. Discuss depth, Lotus etc. sillinesses (both), version issues, alternate readers, example data, elaborations, ...]


Here's an example program:

      package require mime


      # The mime package doesn't know about uuencodings.  Take care of this
      #    later.
      proc is_uuencoded body {
          return 0
      }

      proc print_text_part message {
          if [catch {mime::initialize -string $message} token] {
      puts stderr $token
              # Do some error-handling here.
              exit 1
          }
          print_text_part_t $token  
      }


      proc print_text_part_t token {
          set content [mime::getproperty $token content]
      puts "Looking at $content."
          switch $content {
              application/x-wordperfect6.1  -
              application/ppt  -
              application/pdf  -
              image/jpeg  -
              application/x-gzip  -
              application/msword  -
              application/octet-stream  -
              application/x-tar  -
              application/msword -
              application/x-wordperfect6.1 -
              application/x-msdownload -
              application/x-tar {
                  # Is there anything printable here?
              }                 
              text/html {
                  # How do you want to handle this?
              }
              message/rfc822 -
              TEXT/PLAIN -
              text/rfc822-headers -
              text/enriched -
              text/plain {
                set body [mime::getbody $token]
                if [is_uuencoded $body] {
                }
                puts --------------------------------------\n$body
              }
              message/delivery-status -
              multipart/digest -
              multipart/related -
              multipart/report -
              multipart/alternative -
              multipart/mixed {
                  foreach part [mime::getproperty $token parts] {
                      print_text_part_t $part  
                  }
              }
              default {
                  puts stderr "Whoops!  What is a '$content'?"
              }
          }
      }

      print_text_part $message