Access to a POP3 mailbox

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

    #1

    Access to a POP3 mailbox

    I am in preliminary design of a contact management program. The
    user would like to use his current mail server (POP3 - remote).

    I have done some reading on the IMAP functions but am unclear if
    the following is possible:

    Using the IMAP functions can I write a PHP script to:
    scan the subject lines of all mail in the mailbox ?
    pop just certain messages from the inbox ?
    delete those messages from the inbox ?

    all without disturbing the other messages in his inbox that are
    downloaded to his usual email client (Thunderbird).

    If anyone can suggest a better way to do this, I am all ears.

    bill
  • C.

    #2
    Re: Access to a POP3 mailbox

    On 22 Mar, 11:18, bill <nob...@spamcop .netwrote:
    I am in preliminary design of a contact management program. The
    user would like to use his current mail server (POP3 - remote).
    <snip>
    Using the IMAP functions can I write a PHP script to:
    scan the subject lines of all mail in the mailbox ?
    pop just certain messages from the inbox ?
    delete those messages from the inbox ?
    >
    Yes. Something like...

    $in=imap_open(. ..);
    $msgs=imap_head ers($in); // gets the headers from the currently
    available msgs
    foreach ($msgs as $index=>$header ) {
    if (strstr($header , $look_for)) { // may want to explicitly extract
    the subject
    $email=imap_fet chstructure($in , $index);
    if ($email && save($email)) {
    imap_delete($in , $index);
    }
    }
    }
    imap_expunge($i n);
    imap_close($in) ;
    all without disturbing the other messages in his inbox that are
    downloaded to his usual email client (Thunderbird).
    >
    ....but you need to make sure that he doesn't delete your meassages
    from the mailbox when he downloads the other stuff.
    If anyone can suggest a better way to do this, I am all ears.
    It'd be a lot better to handle the messages synchronously, e.g. with a
    custom procmail script launching the PHP script. But that rather
    depends on having POSIX or similar on the MTA or MUA box.

    C.

    Comment

    • Manuel Lemos

      #3
      Re: Access to a POP3 mailbox

      Hello,

      on 03/22/2007 08:18 AM bill said the following:
      I am in preliminary design of a contact management program. The user
      would like to use his current mail server (POP3 - remote).
      >
      I have done some reading on the IMAP functions but am unclear if the
      following is possible:
      >
      Using the IMAP functions can I write a PHP script to:
      scan the subject lines of all mail in the mailbox ?
      pop just certain messages from the inbox ?
      delete those messages from the inbox ?
      >
      all without disturbing the other messages in his inbox that are
      downloaded to his usual email client (Thunderbird).
      >
      If anyone can suggest a better way to do this, I am all ears.
      You may want to take a look at this POP3 class. You can use the class
      RetrieveMessage function to retrieve just the message headers and get
      only the first body lines you need.

      http://www.phpclasses.org/pop3class

      You can also this MIME message parser class that can decode message and
      extract headers that use non-ASCII characters. I think you need that to
      filter message by subject or sender, as messages with non-ASCII
      characters are encoded with q-encoding like this:

      =?iso-8859-1?Q?

      http://www.phpclasses.org/mimeparser

      --

      Regards,
      Manuel Lemos

      Metastorage - Data object relational mapping layer generator


      PHP Classes - Free ready to use OOP components written in PHP
      http://www.phpclasses.org/

      Comment

      • bill

        #4
        Re: Access to a POP3 mailbox

        C. wrote:
        On 22 Mar, 11:18, bill <nob...@spamcop .netwrote:
        >I am in preliminary design of a contact management program. The
        >user would like to use his current mail server (POP3 - remote).
        <snip>
        >Using the IMAP functions can I write a PHP script to:
        > scan the subject lines of all mail in the mailbox ?
        > pop just certain messages from the inbox ?
        > delete those messages from the inbox ?
        >>
        >
        Yes. Something like...
        >
        $in=imap_open(. ..);
        $msgs=imap_head ers($in); // gets the headers from the currently
        available msgs
        foreach ($msgs as $index=>$header ) {
        if (strstr($header , $look_for)) { // may want to explicitly extract
        the subject
        $email=imap_fet chstructure($in , $index);
        if ($email && save($email)) {
        imap_delete($in , $index);
        }
        }
        }
        imap_expunge($i n);
        imap_close($in) ;

        THank you.
        >
        >all without disturbing the other messages in his inbox that are
        >downloaded to his usual email client (Thunderbird).
        >>
        >
        ...but you need to make sure that he doesn't delete your meassages
        from the mailbox when he downloads the other stuff.
        >
        >If anyone can suggest a better way to do this, I am all ears.
        >
        It'd be a lot better to handle the messages synchronously, e.g. with a
        custom procmail script launching the PHP script. But that rather
        depends on having POSIX or similar on the MTA or MUA box.
        >
        C.
        >
        I don't have control over the MTA, which is on a mail server that
        is not under the same ownership as the php server.
        bill

        Comment

        • bill

          #5
          Re: Access to a POP3 mailbox

          Manuel Lemos wrote:
          Hello,
          >
          on 03/22/2007 08:18 AM bill said the following:
          >I am in preliminary design of a contact management program. The user
          >would like to use his current mail server (POP3 - remote).
          >>
          >I have done some reading on the IMAP functions but am unclear if the
          >following is possible:
          >>
          >Using the IMAP functions can I write a PHP script to:
          > scan the subject lines of all mail in the mailbox ?
          > pop just certain messages from the inbox ?
          > delete those messages from the inbox ?
          >>
          >all without disturbing the other messages in his inbox that are
          >downloaded to his usual email client (Thunderbird).
          >>
          >If anyone can suggest a better way to do this, I am all ears.
          >
          You may want to take a look at this POP3 class. You can use the class
          RetrieveMessage function to retrieve just the message headers and get
          only the first body lines you need.
          >
          http://www.phpclasses.org/pop3class
          >
          You can also this MIME message parser class that can decode message and
          extract headers that use non-ASCII characters. I think you need that to
          filter message by subject or sender, as messages with non-ASCII
          characters are encoded with q-encoding like this:
          >
          =?iso-8859-1?Q?
          >
          http://www.phpclasses.org/mimeparser
          >
          Thank you

          Comment

          Working...