Hoa central
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Hoa\Mail\Content\Content Class Reference
Inheritance diagram for Hoa\Mail\Content\Content:

Public Member Functions

 __construct ()
 
 offsetExists ($header)
 
 offsetGet ($header)
 
 offsetSet ($header, $value)
 
 offsetUnset ($header)
 
 getHeaders ()
 
 getFormattedContent ($headers=true)
 
 getId ()
 
 getIdUrl ()
 
 __toString ()
 

Static Public Member Functions

static formatHeaders (Array $headers)
 
static getAddress ($contact)
 
static getDomain ($contact)
 

Protected Member Functions

 _getContent ()
 

Protected Attributes

 $_headers = []
 

Detailed Description

Class .

Abstract message content.

Definition at line 50 of file Content.php.

Constructor & Destructor Documentation

Hoa\Mail\Content\Content::__construct ( )

Construct a generic content.

Returns
void

Definition at line 66 of file Content.php.

67  {
68  $this['content-transfer-encoding'] = 'base64';
69  $this['content-disposition'] = 'inline';
70 
71  return;
72  }

Member Function Documentation

Hoa\Mail\Content\Content::__toString ( )

Transform this object as a string. Alias of $this->getFormattedContent().

Returns
string

Definition at line 280 of file Content.php.

281  {
282  return $this->getFormattedContent();
283  }
getFormattedContent($headers=true)
Definition: Content.php:171

Here is the call graph for this function:

Hoa\Mail\Content\Content::_getContent ( )
abstractprotected

Get final “plain” content.

Returns
string

Here is the caller graph for this function:

static Hoa\Mail\Content\Content::formatHeaders ( Array  $headers)
static

Get formatted headers.

Parameters
array$headersHeaders.
Returns
string

Definition at line 218 of file Content.php.

219  {
220  $out = null;
221 
222  foreach ($headers as $header => $value) {
223  $value = preg_replace_callback(
224  '#(?<value>[^<]+)(?<tail><[^>]+>)#',
225  function (Array $matches) {
226  return
227  Encoder\QuotedPrintable::encode($matches['value'], true) .
228  $matches['tail'];
229  },
230  $value
231  );
232 
233  $out .= $header . ': ' . $value . CRLF;
234  }
235 
236  return $out;
237  }
static encode($string, $isHeaderValue=false)

Here is the call graph for this function:

static Hoa\Mail\Content\Content::getAddress (   $contact)
static

Extract address from a contact string, such as: Gordon Freeman gordo.nosp@m.n@fr.nosp@m.eeman.nosp@m..net or gordo.nosp@m.n@fr.nosp@m.eeman.nosp@m..net We will get gordo.nosp@m.n@fr.nosp@m.eeman.nosp@m..net.

Returns
string

Definition at line 248 of file Content.php.

249  {
250  if (0 !== preg_match('#[^<]*<(?<address>[^>]+)#', $contact, $match)) {
251  return $match['address'];
252  }
253 
254  return trim($contact);
255  }
static Hoa\Mail\Content\Content::getDomain (   $contact)
static

Get domain of an adress from a contact string. With the example of self::getAddress, we will get freeman.net.

Returns
string

Definition at line 263 of file Content.php.

264  {
265  $address = static::getAddress($contact);
266 
267  if (false !== $pos = strpos($address, '@')) {
268  return substr($address, $pos + 1);
269  }
270 
271  return $address;
272  }
Hoa\Mail\Content\Content::getFormattedContent (   $headers = true)

Get final formatted content.

Parameters
bool$headersWith headers or not.
Returns
string

Definition at line 171 of file Content.php.

172  {
173  $out = null;
174 
175  if (true === $headers) {
176  $out .= static::formatHeaders($this->getHeaders()) . CRLF;
177  }
178 
179  $out .= $this->_getContent();
180 
181  return $out;
182  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Mail\Content\Content::getHeaders ( )

Get all headers.

Returns
array

Definition at line 153 of file Content.php.

154  {
155  return $this->_headers;
156  }

Here is the caller graph for this function:

Hoa\Mail\Content\Content::getId ( )

Get Content-ID of this content. Please, see RFC2111.

If ID does not exist, a random one will be generated.

Returns
string

Definition at line 192 of file Content.php.

193  {
194  if (!isset($this['content-id'])) {
195  $this['content-id'] = '<' . md5(uniqid()) . '*mail@hoa-project.net>';
196  }
197 
198  return trim($this['content-id'], '<>');
199  }

Here is the caller graph for this function:

Hoa\Mail\Content\Content::getIdUrl ( )

Get URL of this content. Please, see RFC2111.

Returns
string

Definition at line 207 of file Content.php.

208  {
209  return 'cid:' . $this->getId();
210  }

Here is the call graph for this function:

Hoa\Mail\Content\Content::offsetExists (   $header)

Check whether a header is defined.

Parameters
string$headerHeader.
Returns
bool

Definition at line 80 of file Content.php.

81  {
82  $header = mb_strtolower($header);
83 
84  return true === array_key_exists($header, $this->_headers);
85  }

Here is the caller graph for this function:

Hoa\Mail\Content\Content::offsetGet (   $header)

Get a specific header.

Parameters
string$headerHeader.
Returns
string

Definition at line 93 of file Content.php.

94  {
95  $header = mb_strtolower($header);
96 
97  if (false === $this->offsetExists($header)) {
98  return null;
99  }
100 
101  return $this->_headers[$header];
102  }

Here is the call graph for this function:

Hoa\Mail\Content\Content::offsetSet (   $header,
  $value 
)

Set a header.

Parameters
string$headerHeader.
string$valueValue.
Returns
string

Definition at line 111 of file Content.php.

112  {
113  $header = mb_strtolower($header);
114 
115  if (true === $this->offsetExists($header)) {
116  $old = $this->_headers[$header];
117  } else {
118  $old = null;
119  }
120 
121  if (0 !== preg_match('#[' . CRLF . ']#', $value)) {
122  throw new Mail\Exception\Security(
123  'Header “%s” contains illegal character.',
124  0,
125  $header
126  );
127  }
128 
129  $this->_headers[$header] = $value;
130 
131  return $old;
132  }

Here is the call graph for this function:

Hoa\Mail\Content\Content::offsetUnset (   $header)

Unset a header.

Parameters
string$headerHeader.
Returns
void

Definition at line 140 of file Content.php.

141  {
142  $header = mb_strtolower($header);
143  unset($this->_headers[$header]);
144 
145  return;
146  }

Member Data Documentation

Hoa\Mail\Content\Content::$_headers = []
protected

Definition at line 57 of file Content.php.


The documentation for this class was generated from the following file: