Zend_Mail: moveMessage () exception

According to the documentation, you should use the getNumberByUniqueId () method to get the message identifier when moving / deleting messages. However, as before, I get an exception that occurs partly by processing the folder: "only identifier not found in response."

The code used goes line by line:

try {
  $emailAddresses = array ();
  $invalidAddresses = array ();
  $errors = array();

  $emailValidator = new Zend_Validate_EmailAddress ();
  $trimFilter = new Zend_Filter_StringTrim ();

  $mail = new Zend_Mail_Storage_Imap (...);  
  $mail->selectFolder ( '/Unsubscribe' );

  echo 'There are ' . $mail->countMessages () . " messages to process\n";

  foreach ( $mail as $messageId => $message ) {
    try {
      $mail->noop ();
      $recipientMatch = $trimFilter->filter ( str_ireplace ( 'REMOVE ', '', $message->subject ) );

      if (! substr_count ( $recipientMatch, '@' )) {
        // Try the sender if the subject line doesn't have an address in
        $matches = array ();
        $from = $message->getHeader ( 'from' );
        preg_match ( '/<(.+@.+)>/', $from, $matches );

        if (sizeof ( $matches ) == 2) {
          $recipientMatch = $matches [1];
        } else {
          $recipientMatch = $from;
        }
      }

      if (! $emailValidator->isValid ( $recipientMatch )) {
        $invalidAddresses [] = $recipientMatch;
        continue;
      }

      $emailAddresses [] = $recipientMatch;
      $messageUniqueId = $mail->getUniqueId ( $messageId );
      $mail->moveMessage ( $mail->getNumberByUniqueId ( $messageUniqueId ), '/Unsubscribe/done' );
    } catch ( Exception $e ) {
      $errors[] = array($recipientMatch , $e);
    }
  }
} catch ( Zend_Mail_Storage_Exception $e ) {
  echo "There was a problem processing the mail account\n", $e->getMessage ();
} catch ( Exception $e ) {
  echo "There was an unmatched exception\n", $e->getMessage ();
}

Any ideas on which an exception is thrown (Zend Framework v1.10.8)?

Stack Trace for Exception:

#0 /usr/share/php/libzend-framework-php/Zend/Mail/Storage/Imap.php(163): Zend_Mail_Protocol_Imap->fetch(Array, 4)
#1 /usr/share/php/libzend-framework-php/Zend/Mail/Storage/Abstract.php(307): Zend_Mail_Storage_Imap->getMessage(4)
#2 /tmp/unsubscribe.php(29): Zend_Mail_Storage_Abstract->current()
#3 /tmp/dummy.php(1): include('/tmp/unsubscribe.php')
#4 {main}

The contents of the array used in Zend_Mail_Protocol_Imap->fetch()are:

Array(
   0 => 'FLAGS', 
   1 => 'RFC822.HEADER'
)
+3
source share
2 answers

. $messageId , . $messageId "" (, "--Bounce" ). .

: , moveMessage - , getNumberByUniqueId!

, , , moveMessage ($ id, $folder) moveMessage ($ index, $folder). . , .

+3

... , : " " , , , , , : http://framework.zend.com/issues/browse/ZF-5655

"while" ACTUAL , :

while($next_id = $gmail->getUniqueId()) {
  // move message to label folder "My_archive_folder"
  $gmail->moveMessage($next_id, 'My_archive_folder');
}
+1

Source: https://habr.com/ru/post/1774906/


All Articles