imap_delete() doesn't work right.

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

    #1

    imap_delete() doesn't work right.

    Anyone know why this code just deletes random messages and not ALL the
    messages? $this->headers is simply imap_headers()

    $i=0;
    foreach ($this->headers as $header){

    #Trim the header
    $header = trim($header);
    #Retrieve the ID of the mesage.
    if (substr($header ,0,2) === 'U ' ||
    substr($header, 0,2) === 'N '){

    $header = substr($header, 2);

    if (substr($header ,1,1) === 'D'){
    $header = substr($header, 2);
    $header = trim($header);
    }

    $msg_id_array = explode(')',$he ader);
    $msg_id = trim($msg_id_ar ray[0]);

    $h = imap_headerinfo ($this->mbox ,
    $msg_id);

    if ($h->Unseen === 'U' || $h->Recent
    === 'N'){
    $this->messages[$i]['id'] =
    $msg_id;
    $this->messages[$i]['from'] =
    $h->fromaddress;
    $this->messages[$i]['body'] =
    trim(imap_fetch body($this->mbox , $msg_id , 1));
    $uid = imap_uid($this->mbox ,
    $h->Msgno);
    imap_delete ($this->mbox ,
    $uid , FT_UID);
    imap_expunge($t his->mbox);
    $i++;
    }
    } else {
    print "Invalid header:
    \"$header\"\r\n ";
    }
    }
Working...