Skip to content

Commit ed7b5b6

Browse files
committed
Merge pull request #8 from czPechy/master
Added Contact class, getSender function
2 parents 106b07a + df4e0da commit ed7b5b6

File tree

3 files changed

+86
-10
lines changed

3 files changed

+86
-10
lines changed

MailLibrary/Contact.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* @author Martin Pecha
4+
*/
5+
6+
namespace greeny\MailLibrary;
7+
8+
/**
9+
* Class Contact
10+
* @package greeny\MailLibrary
11+
*/
12+
class Contact {
13+
14+
/** @var string */
15+
private $mailbox;
16+
/** @var string */
17+
private $host;
18+
/** @var string */
19+
private $personal;
20+
/** @var string */
21+
private $adl;
22+
23+
/**
24+
* @param $mailbox
25+
* @param $host
26+
* @param $personal
27+
* @param $adl
28+
*/
29+
public function __construct($mailbox=NULL, $host=NULL, $personal=NULL, $adl=NULL) {
30+
$this->mailbox = $mailbox;
31+
$this->host = $host;
32+
$this->personal = $personal;
33+
$this->adl = $adl;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
public function __toString() {
40+
$address = $this->getName() ? "\"" . $this->getName(). "\" " : "";
41+
$address .= $this->getAdl() ? $this->getAdl().":" : "";
42+
$address .= "<".$this->getEmail().">";
43+
return $address;
44+
}
45+
46+
/**
47+
* @return string
48+
*/
49+
public function getEmail() {
50+
return $this->mailbox."@".$this->host;
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
public function getName() {
57+
return $this->personal;
58+
}
59+
60+
/**
61+
* @return string
62+
*/
63+
public function getAdl() {
64+
return $this->adl;
65+
}
66+
67+
}

MailLibrary/ContactList.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@ class ContactList implements Iterator, Countable{
1515

1616
public function addContact($mailbox = NULL, $host = NULL, $personal = NULL, $adl = NULL)
1717
{
18-
$this->contacts[] = array(
19-
'mailbox' => $mailbox,
20-
'host' => $host,
21-
'personal' => $personal,
22-
'adl' => $adl,
23-
);
18+
$this->contacts[] = new Contact($mailbox,$host,$personal,$adl);
2419
}
2520

2621
public function build()
2722
{
2823
$return = array();
24+
/** @var Contact $contact */
2925
foreach($this->contacts as $contact) {
30-
$address = $contact['personal'] ? "\"" . $contact['personal']. "\" " : "";
31-
$address .= $contact['adl'] ? $contact['adl'].":" : "";
32-
$address .= "<".$contact['mailbox']."@".$contact['host'].">";
33-
$return[] = $address;
26+
$return[] = $contact->__toString();
3427
}
3528
$this->builtContacts = $return;
3629
}
@@ -40,6 +33,14 @@ public function getContacts()
4033
return $this->builtContacts;
4134
}
4235

36+
/**
37+
* @return array
38+
*/
39+
public function getContactsObjects()
40+
{
41+
return $this->contacts;
42+
}
43+
4344
public function __toString()
4445
{
4546
return implode(', ', $this->builtContacts);

MailLibrary/Mail.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ public function delete()
203203
$this->connection->getDriver()->deleteMail($this->id);
204204
}
205205

206+
/**
207+
* @return Contact|null
208+
*/
209+
public function getSender() {
210+
$contacts = $this->from->getContactsObjects();
211+
return (!empty($contacts[0]) ? $contacts[0] : null);
212+
}
213+
206214
/**
207215
* Initializes headers
208216
*/

0 commit comments

Comments
 (0)