Skip to content

Commit

Permalink
Handle base64 encoded messages and quoted messages.
Browse files Browse the repository at this point in the history
See: #226
  • Loading branch information
kovshenin committed Jul 9, 2015
1 parent fae4ece commit 97c1e07
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions classes/class-supportflow-email-replies.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ public function download_and_process_email_replies( $connection_details ) {

$email->headers = imap_headerinfo( $imap_connection, $email->msgno );
$email->structure = imap_fetchstructure( $imap_connection, $email->msgno );
$email->body = $this->get_body_from_connection( $imap_connection, $email->msgno );
$email->body = imap_qprint( imap_body( $imap_connection, $email->msgno ) );

if ( imap_base64( $email->body ) ) {
$email->body = imap_base64( $email->body );
}

$email->body = imap_utf8( $email->body );

if ( 0 === strcasecmp( $connection_details['username'], $email->headers->from[0]->mailbox . '@' . $email->headers->from[0]->host ) ) {
$connection_details['password'] = '[redacted]'; // redact the password to avoid unnecessarily exposing it in logs
Expand All @@ -161,16 +167,6 @@ public function download_and_process_email_replies( $connection_details ) {
continue;
}

// Convert encoding to UTF-8
if ( ! empty( $email->structure->parameters ) ) {
foreach ( $email->structure->parameters as $parameter ) {
if ( 'CHARSET' == $parameter->attribute ) {
$email->body = iconv( $parameter->value, 'UTF-8', $email->body );
break;
}
}
}

// @todo Confirm this a message we want to process
$result = $this->process_email( $imap_connection, $email, $email->msgno, $connection_details['username'], $connection_details['account_id'] );

Expand Down

0 comments on commit 97c1e07

Please sign in to comment.