diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/EmailMessage.php | 10 | ||||
-rw-r--r-- | src/Message.php | 2 | ||||
-rw-r--r-- | src/PhpBB3Impl.php | 23 | ||||
-rw-r--r-- | src/PhpBB3Message.php | 4 |
4 files changed, 34 insertions, 5 deletions
diff --git a/src/EmailMessage.php b/src/EmailMessage.php index 6c025ab..dd25045 100644 --- a/src/EmailMessage.php +++ b/src/EmailMessage.php @@ -68,6 +68,16 @@ abstract class EmailMessage implements Message { return $from[0]['address']; } + public function getFromDisplayName() { + $from = mailparse_rfc822_parse_addresses($this->getHeader('from')); + if ($from[0]['address'] != $from[0]['display']) { + return $from[0]['display']; + } + else { + return ''; + } + } + public function getSubject() { return $this->getHeader('subject'); } diff --git a/src/Message.php b/src/Message.php index 1a7f7f4..bfe46da 100644 --- a/src/Message.php +++ b/src/Message.php @@ -25,6 +25,8 @@ interface Message { public function getFrom(); + public function getFromDisplayName(); + public function getSubject(); public function getMessageId(); diff --git a/src/PhpBB3Impl.php b/src/PhpBB3Impl.php index de61c5b..cc6d400 100644 --- a/src/PhpBB3Impl.php +++ b/src/PhpBB3Impl.php @@ -193,12 +193,25 @@ class PhpBB3Impl implements PhpBB3 { $userId = $this->getUserId($msg->getFrom()); if ($userId === false) { - throw new Exception('unrecognized email address: ' . $msg->getFrom()); - } + $userId = ANONYMOUS; - $userName = $this->getUserName($userId); - if ($userName === false) { - throw new Exception('unrecognized user id: ' . $userId); + $dispname = $msg->getFromDisplayName(); + if ($dispname === '') { + $userName = $msg->getFrom(); + } + else { + $userName = $dispname . ' (' . $msg->getFrom() . ')'; + } + if (validate_username($userName, '') !== false) { + $userName = 'EMail Poster'; + } + } + else + { + $userName = $this->getUserName($userId); + if ($userName === false) { + throw new Exception('unrecognized user id: ' . $userId); + } } $subject = $msg->getSubject(); diff --git a/src/PhpBB3Message.php b/src/PhpBB3Message.php index d31de1c..ef5a397 100644 --- a/src/PhpBB3Message.php +++ b/src/PhpBB3Message.php @@ -44,6 +44,10 @@ class PhpBB3Message implements Message { . $this->user->data['user_email'] . '>'; } + public function getFromDisplayName() { + return $this->user->data['username']; + } + public function getSubject() { return $this->post['post_subject']; } |