Handling emails

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

    #1

    Handling emails

    *************** ********
    Your mail has been scanned by InterScan MSS.
    *************** ********


    Hello,

    I'd like to ask some clue to move further on my project :-)
    The purpose would be to gather all emails (local and remote ones) to do some
    backup.
    I've tried to get ideas by reading all about the modules enclose with python,
    but neither email framework nor mailbox give me the idea how to handle *one*
    email complete of payload and attachment (if any).
    This purpose will give me chance to avoid duplicates and I suppose to achieve
    the grade of making a maildir o mbox file.
    It's welcome to point me to useful information. Surely I'm not asking
    ready-made solution :-).

    BTW sorry to whom feel hurt by the "virus scan banner". That's not generated
    by me, but rather by my ISP. I'll try to contact my ISP and ask to move it
    off from the email body.

    F


  • Gerard Flanagan

    #2
    Re: Handling emails


    Fulvio wrote:
    >
    Hello,
    >
    I'd like to ask some clue to move further on my project :-)
    The purpose would be to gather all emails (local and remote ones) to do some
    backup.
    I've tried to get ideas by reading all about the modules enclose with python,
    but neither email framework nor mailbox give me the idea how to handle *one*
    email complete of payload and attachment (if any).
    The 'PopClient' class here might help you:



    A script I use is here:



    There's a woeful lack of comments but hopefully you can figure it out!
    It saves emails to the filesystem along with attachments. (Note that
    the POP account passwords are stored as plain text.) It checks a mail's
    message-id and doesn't download if it already has been downloaded.

    hth

    Gerard

    Comment

    • Fulvio

      #3
      Re: Handling emails

      *************** ********
      Your mail has been scanned by InterScan MSS.
      *************** ********


      On Tuesday 24 October 2006 01:12, Dennis Lee Bieber wrote:
      Message-id:
      <96D4BF841562DA 44A7935AAC90A29 D6405E5611B@ems s01m12.us.lmco. com>
      >
      as the ID is generally created when the message is submitted to the
      delivery system
      Well, that's what I'm dealing with, since a couple of weeks :-) indeed.
      Some might not have one, but Kmail should had fixed.
      The second will be the way to get the whole email from the mbox file. My
      problem still remain, partially. I'm not sure if the below procedure will
      give me the emails off including multipart ones.

      8<-------------8<-------------8<-------------8<-------------8<-------------
      #! /usr/bin/env python

      from __future__ import generators

      import email, re
      import mailbox
      import email.Message

      def getmbox(name):
      """Return an mbox iterator given a file/directory/folder name."""
      fp = open(name, "rb")
      mbox = mailbox.Portabl eUnixMailbox(fp , get_message)
      return iter(mbox)

      def get_message(obj ):
      """Return an email Message object."""

      if isinstance(obj, email.Message.M essage):
      return obj
      # Create an email Message object.
      if hasattr(obj, "read"):
      obj = obj.read()
      try:
      msg = email.message_f rom_string(obj)
      except email.Errors.Me ssageParseError :

      obj = obj[len(headers):]
      msg = email.Message.M essage()
      return msg

      header_break_re = re.compile(r"\r ?\n(\r?\n)")

      def extract_headers (text):
      """Very simple-minded header extraction"""

      m = header_break_re .search(text)
      if m:
      eol = m.start(1)
      text = text[:eol]
      if ':' not in text:
      text = ""
      return text

      if __name__ == '__main__':
      #simple trial with local mbox file
      import sys
      try:
      file =sys.argv[1]
      except IOError:
      print 'Must give a mbox file program /path/to_mbox'
      sys.exit()
      k = getmbox(file)
      while 1:
      full_email = get_message(k.n ext())
      print '%78s' %full_email
      answer= raw_input('More ? Y/N')
      if answer.lower() == 'n': break

      8<-------------8<-------------8<-------------8<-------------8<-------------
      I admit that not all code is my genuine design, ;-) some other programs
      extrapolating have been done.

      F


      Comment

      • Fulvio

        #4
        Re: Handling emails

        *************** ********
        Your mail has been scanned by InterScan MSS.
        *************** ********


        On Tuesday 24 October 2006 03:07, Gerard Flanagan wrote:
        The 'PopClient' class here might help you:
        Thank you, both for the replies.
        Gerard,
        Surely I'll peep on that code ;-) to gather a wider perspective. A small
        negative point is that for pop deals I've gotten a good success :-) But I
        don't give up, perhaps it there'll be some good idea.
        I'm more interested for the IMAP side of the issue, even I might avoid for my
        own purposes.

        Last, suppose to publish the "thing" where will it be the appropriate site?
        At the present my program can do filtering and sincronizing with local MUA
        trash. Small problems with IMAP protocol, but it may work for POP3 or IMAP4
        on regex filter options. Alfa testers (cooperators) needed ;-)

        F


        Comment

        • Fulvio

          #5
          Re: Handling emails

          *************** ********
          Your mail has been scanned by InterScan MSS.
          *************** ********


          On Tuesday 24 October 2006 03:07, Gerard Flanagan wrote:
          The 'PopClient' class here might help you:
          I got a look rather later. Let me say that is impressively pythonic :-)
          On the other hand I've to go deep on learning the use of Python classes, as
          much as the POPClient likes a different config file and will upset a big
          chunk of my code.
          Functions are good, I'll study the emails handling, only I need some time to
          prepair a method to discern local and remote emails and a way to save/recover
          the most important ones.

          F

          Comment

          • Gerard Flanagan

            #6
            Re: Handling emails


            Fulvio wrote:
            On Tuesday 24 October 2006 03:07, Gerard Flanagan wrote:
            The 'PopClient' class here might help you:
            >
            I got a look rather later. Let me say that is impressively pythonic :-)
            I don't know if everyone would agree with you, but thanks!

            Have you looked at the email.utils module? Some useful functions there.

            All the best

            Gerard

            Comment

            • Fulvio

              #7
              Re: Handling emails

              *************** ********
              Your mail has been scanned by InterScan MSS.
              *************** ********


              On Wednesday 25 October 2006 13:06, Dennis Lee Bieber wrote:
              # based upon bits from the (Active)Python 2.4 help system and other
              code...
              OK, good help, Thank you.
              As I had confessed, that code was extrapolated from other sources and I took
              it for granted as long as is working on my purpose.
              Most of my purpose is to get the whole mail. Last function has no use.
              Both code doing well the only difference is the way to call
              email.message_f rom_(file|strin g)

              F


              Comment

              • Ben Finney

                #8
                Re: Handling emails

                Fulvio <fulvio@tm.net. mywrites:
                *************** ********
                Your mail has been scanned by InterScan MSS.
                *************** ********
                Please stop sending messages with obnoxious headers like this.

                Comment

                • Steve Holden

                  #9
                  Re: Handling emails

                  Ben Finney wrote:
                  Fulvio <fulvio@tm.net. mywrites:
                  >
                  >
                  >>************* **********
                  >>Your mail has been scanned by InterScan MSS.
                  >>************* **********
                  >
                  >
                  Please stop sending messages with obnoxious headers like this.
                  >
                  Please stop sending messages with obnoxious content like this.

                  If you insist on telling someone off publicly via a newsgroup, once is
                  enough. I agree it's a pain, but Fulvio may not have it in his power to
                  switch the header off. Mail admins do some incredibly stupid things.

                  regards
                  Steve
                  --
                  Steve Holden +44 150 684 7255 +1 800 494 3119
                  Holden Web LLC/Ltd http://www.holdenweb.com
                  Skype: holdenweb http://holdenweb.blogspot.com
                  Recent Ramblings http://del.icio.us/steve.holden

                  Comment

                  • Ben Finney

                    #10
                    Re: Handling emails

                    Steve Holden <steve@holdenwe b.comwrites:
                    Please stop sending messages with obnoxious content like this.
                    Yes, I guess I should have expected a response like that from someone
                    :-)
                    If you insist on telling someone off publicly via a newsgroup, once
                    is enough.
                    Apparently not. I tried initially contacting him privately. Then I
                    tried explaining in a (single) message to the list.
                    I agree it's a pain, but Fulvio may not have it in his power to
                    switch the header off. Mail admins do some incredibly stupid things.
                    There is always the option to not send messages to this list using
                    that mail server. I don't care what option is taken, so long as the
                    useless and obnoxious headers on his messages stop.

                    --
                    \ Lucifer: "Just sign the Contract, sir, and the Piano is yours." |
                    `\ Ray: "Sheesh! This is long! Mind if I sign it now and read it |
                    _o__) later?" -- http://www.achewood.com/ |
                    Ben Finney

                    Comment

                    • Peter Decker

                      #11
                      Re: Handling emails

                      On 10/26/06, Ben Finney <bignose+hate s-spam@benfinney. id.auwrote:
                      I agree it's a pain, but Fulvio may not have it in his power to
                      switch the header off. Mail admins do some incredibly stupid things.
                      >
                      There is always the option to not send messages to this list using
                      that mail server. I don't care what option is taken, so long as the
                      useless and obnoxious headers on his messages stop.
                      >
                      --
                      \ Lucifer: "Just sign the Contract, sir, and the Piano is yours." |
                      `\ Ray: "Sheesh! This is long! Mind if I sign it now and read it |
                      _o__) later?" -- http://www.achewood.com/ |
                      Ben Finney
                      >
                      Ah, but obnoxious footers are OK, I guess.

                      --

                      # p.d.

                      Comment

                      • Ben Finney

                        #12
                        Re: Handling emails

                        "Peter Decker" <pydecker@gmail .comwrites:
                        On 10/26/06, Ben Finney <bignose+hate s-spam@benfinney. id.auwrote:
                        There is always the option to not send messages to this list using
                        that mail server. I don't care what option is taken, so long as
                        the useless and obnoxious headers on his messages stop.

                        --
                        \ Lucifer: "Just sign the Contract, sir, and the Piano is yours." |
                        `\ Ray: "Sheesh! This is long! Mind if I sign it now and read it |
                        _o__) later?" -- http://www.achewood.com/ |
                        Ben Finney
                        >
                        Ah, but obnoxious footers are OK, I guess.
                        I guess. I maintain that there *is* a qualitative difference between a
                        spammy header block, irrelevant to the message content but intruding
                        upon it, at the top of the message; and a dignature block at the
                        bottom, *after* all the relevant material, separated by a standard
                        signature block separator.

                        --
                        \ "I doubt, therefore I might be." -- Anonymous |
                        `\ |
                        _o__) |
                        Ben Finney

                        Comment

                        • Fulvio

                          #13
                          Re: Handling emails

                          *************** ********
                          Your mail has been scanned by InterScan MSS.
                          *************** ********


                          On Friday 27 October 2006 06:48, Ben Finney wrote:
                          There is always the option to not send messages to this list using
                          that mail server
                          Once again sorry for that. I'll take action to switch to another mailserver.
                          Thank for the advice

                          F


                          Comment

                          • Ben Finney

                            #14
                            Re: Handling emails

                            Fulvio <fulvio@tm.net. mywrites:
                            On Friday 27 October 2006 06:48, Ben Finney wrote:
                            There is always the option to not send messages to this list using
                            that mail server
                            >
                            Once again sorry for that. I'll take action to switch to another
                            mailserver. Thank for the advice
                            That would be very much appreciated, thank you.

                            --
                            \ "Consider the daffodil. And while you're doing that, I'll be |
                            `\ over here, looking through your stuff." -- Jack Handey |
                            _o__) |
                            Ben Finney

                            Comment

                            Working...