The lib email parse problem...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 叮叮当当

    #16
    Re: The lib email parse problem...

    yes, the special is i must choose exactly one section to destruct,
    instead of processing all subparts.


    John Machin 写道:
    Tim Roberts wrote:
    "????" <guotie.9@gmail .comwrote:
    >i know how to use email module lib.
    >
    >the question is about how to handle the rfc 1521 mime
    >mulitpart/alternitave part .
    >
    >i know emai can handle mulitpart , but the subpart alternative is
    >special .
    No, it's not. A multipart/alternative section is constructed exactly the
    same as any other multipart section. It just so happens that it will have
    exactly two subsections, one text/plain and one text/html.
    >
    I was under the impression that it was a little more general than that
    ... see e.g. http://www.freesoft.org/CIE/RFC/1521/18.htm
    >
    My guess is that the OP meant special in the sense that the reader
    needs to choose one subpart, instead of processing all subparts.
    >
    Cheers,
    John
    >
    >
    >
    >
    --
    - Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

    Comment

    • John Machin

      #17
      Re: The lib email parse problem...

      On 30/08/2006 4:44 PM, 叮叮当当 wrote:
      yes, the special is i must choose exactly one section to destruct,
      instead of processing all subparts.
      So have you tried to use the example I posted yesterday? Do you still
      have any problems? Note: it is generally a good idea to post a message
      when you have overcome a problem -- that lets would-be helpers know that
      they are "off the case" :-)

      Cheers,
      John

      Comment

      • neoedmund

        #18
        Re: The lib email parse problem...

        myself wrote a multipart parser in java(i customise it because i need
        get information of "upload progress"). and i think it's also easy to
        implement in python, i've not have time done it, or i'll post it.
        but if you're no other special needs, just use email lib, it's quick to
        program and if you really not need some part, just drop it.
        there's anything wrong with email lib?

        叮叮当当 wrote:
        yes, the special is i must choose exactly one section to destruct,
        instead of processing all subparts.
        >
        >
        John Machin 写道:
        >
        Tim Roberts wrote:
        "????" <guotie.9@gmail .comwrote:
        >
        i know how to use email module lib.

        the question is about how to handle the rfc 1521 mime
        mulitpart/alternitave part .

        i know emai can handle mulitpart , but the subpart alternative is
        special .
        >
        No, it's not. A multipart/alternative section is constructed exactlythe
        same as any other multipart section. It just so happens that it willhave
        exactly two subsections, one text/plain and one text/html.
        I was under the impression that it was a little more general than that
        ... see e.g. http://www.freesoft.org/CIE/RFC/1521/18.htm

        My guess is that the OP meant special in the sense that the reader
        needs to choose one subpart, instead of processing all subparts.

        Cheers,
        John



        --
        - Tim Roberts, timr@probo.com
        Providenza & Boekelheide, Inc.

        Comment

        • 叮叮当当

          #19
          Re: The lib email parse problem...

          thanks.

          i have use a temp method to overcome it .

          i still think the email lib should give the boundary border to parse
          mail.

          code is as following:

          def parse_mail_cont ent(self, mail):
          content = ''
          alter = False
          subty = ''
          html = ''
          plain = ''
          for part in mail.walk():
          if part.is_multipa rt():
          if part.get_conten t_subtype() == 'alternative':
          alter = True
          else:
          alter = False
          continue
          if part.get_conten t_maintype() == 'text':
          if part.get_filena me():
          continue
          ty = part.get_conten t_subtype()
          ch = part.get_conten t_charset()
          if alter and ty == 'plain':
          subty = 'plain'
          if ch:
          plain = unicode(part.ge t_payload(decod e =
          True),ch).encod e('utf-8')
          else:
          plain = part.get_payloa d(decode =
          True).decode('g b2312').encode( 'utf-8')
          elif alter and ty == 'html':
          subty = 'html'
          if ch:
          html = unicode(part.ge t_payload(decod e =
          True),ch).encod e('utf-8')
          else:
          html = part.get_payloa d(decode =
          True).decode('g b2312').encode( 'utf-8')
          elif not alter:
          if subty == 'html':
          content += html
          elif subty == 'plain':
          content += plain
          alter = False
          subty = ''
          if ch:
          content += unicode(part.ge t_payload(decod e =
          True),ch).encod e('utf-8')
          else:
          content += part.get_payloa d(decode =
          True).decode('g b2312').encode( 'utf-8')
          elif alter:
          if subty == 'html':
          content += html
          elif subty == 'plain':
          content += plain
          alter = False
          subty = ''
          if alter:
          if subty == 'html':
          content += html
          elif subty == 'plain':
          content += plain
          return content

          thanks very much.

          John Machin wrote:
          On 30/08/2006 4:44 PM, 叮叮当当 wrote:
          yes, the special is i must choose exactly one section to destruct,
          instead of processing all subparts.
          >
          So have you tried to use the example I posted yesterday? Do you still
          have any problems? Note: it is generally a good idea to post a message
          when you have overcome a problem -- that lets would-be helpers know that
          they are "off the case" :-)

          Cheers,
          John

          Comment

          • Fredrik Lundh

            #20
            Re: The lib email parse problem...

            "????" wrote:
            i have use a temp method to overcome it .
            >
            i still think the email lib should give the boundary border to parse
            mail.
            the email lib you're using is a PARSER, and it's already PARSING the
            mail for you.

            (if you have trouble structuring your program when someone else is doing
            the parsing for you, what makes you think it would be easier if you had to
            do the parsing yourself as well ?)

            wrt. your temp method, I think you'll find that a recursive solution would
            be a lot easier to get right without having to resort to code duplication like
            in your example; I think John Machin posted an example earlier in this
            thread.

            </F>



            Comment

            Working...