SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why imap_delete really delete the message instead of marking it for deletion?

    Have anyone used imap_delete before? I'm trying to mark a message for deletion with imap_delete but instead it was really deleting the message. I checked in squirrelmail it's gone from inbox. When I executed the code again it goes straight to die("Couldn't get emails") when calling imap_headers. And printing imap_errors returns empty.

    Is there some setting I need to configure first? Is there any way to mark a message for deletion?

    Thanks

    PHP Code:
    $conn imap_open($this->imapPath."INBOX",$this->username,$this->password) or die("Connection to server failed");
    $headers imap_headers($conn) or die("Couldn't get emails");
    $mailnumbers imap_search($conn,"UNDELETED");

    foreach(
    $mailnumbers as $i) {
      
    $mailHeader = @imap_headerinfo($conn$i);
      
    $mailfrom $mailHeader->from;
      
    $objfrom $mailfrom[0];
      
    $from $objfrom->mailbox "@" $objfrom->host;

      
    $body imap_body($conn,$i);
      
    // ...store message body to db
      
    imap_delete($conn$i);
    }
    imap_close($conn); 

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    If you change it to
    Code PHP:
    $conn = imap_open($this->imapPath."INBOX",$this->username,$this->password) or die("Connection to server failed");
     
    $headers = imap_headers($conn) or die("Couldn't get emails");
    $mailnumbers = imap_search($conn,"UNDELETED");
     
    foreach($mailnumbers as $i) {
      $mailHeader = @imap_headerinfo($conn, $i);
      $mailfrom = $mailHeader->from;
      $objfrom = $mailfrom[0];
      $from = $objfrom->mailbox . "@" . $objfrom->host;
     
      $body = imap_body($conn,$i);
      // ...store message body to db
      imap_delete($conn, $i);
    }
     
    foreach($mailnumbers as $j) {
      imap_undelete($conn, $j);
    }
     
    imap_close($conn);
    do they "reappear" in SquirrelMail? Have they been deleted or are they inside some kind of "email purgatory"?

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mittineague,

    When I add imap_undelete like you suggested, the messages didn't get deleted, but the old ones that were accidently deleted through imap_delete still won't show up. I also check the qmail directories under cur, new, tmp, .Trash/cur, .Trash/new, .Trash/tmp, they're not there. It's as if the imap_close automatically calls imap_expunge before actually closing the connection.

    I wonder if anyone had this experience before, and whether this is a PHP problem or a mail server/web hosting problem?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,449
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I'm guesing it must be some kind of server clean-up (CRON job?) the host has running. AFAIK the only way imap_delete() should actually delete is if a third argument of CL_EXPUNGE is passed to it. If the constant's value is 32768 then it seems like even if your code was written wrong ($conn, $i, $i) and $i reached that, even then only the one should actually get deleted.

    No, I think your host is running a clean-up script.

  5. #5
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I'll submit a ticket to ask my webhost about this. Thanks for your help so far


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •