Header Class
This class handles the email header data.
Important: All of these functions are available through the message object returned by the Peeker class. Notated here as: $e
Message Object Property Access Functions
get_fingerprint()
Returns MD5 hash of several basic email message properties (default: fromaddress, toaddress, subject, date). This allows you to determine if an email is unique (like a fingerprint). The fingerprint can also be used to generate a unique directory name for storing attachments. The fingerprint is not the Message-ID.
$e->get_fingerprint();
get_date()
Returns the raw date string from the email message.
$e->get_date();
get_subject()
Return the fully-decoded subject of the email message.
$e->get_subject();
get_msgno()
Return the message number of the email. This is a temporary number given by the server to the message. The message number changes when the email queue is changed. E.g., msgno 1 is the first message in the queue.
$e->get_msgno();
get_message_id()
Returns the Message-ID header (if there is one).
$e->get_message_id();
get_to()
Returns the fully-decoded To address string.
$e->get_to();
get_from()
Returns the fully-decoded From address string.
$e->get_from();
get_reply_to()
Returns the fully-decoded Reply-To address string.
$e->get_reply_to();
get_sender()
Returns the fully-decoded Sender address string.
$e->get_sender();
get_cc()
Returns the fully-decoded CC address string.
$e->get_cc();
get_bcc()
Returns the fully-decoded BCC address string. Note: the BCC field generally only appears in outgoing messages (such as those in an IMAP Drafts folder).
$e->get_bcc();
get_return_path()
Returns the fully-decoded Return-Path address string.
$e->get_return_path();
get_to_array([$format])
Returns the fully-decoded To address array. By default, the array holds multiple addresses, each with its own personal, mailbox, and host part. This is the same address array returned by the imap_headerinfo() function except that this array is fully-decoded.
Send the optional $format argument to get a flat array. The array values will be formatted with string replacement on these three keywords: personal, mailbox, host. So if you just want the email address without the personal part (e.g., me@example.com) then send the string 'mailbox@host' as the format argument. The $format string can contain any other strings.
$e->get_to_array(); // no argument, returns nested associative array.
$e->get_to_array('"personal" <mailbox@host>'); // returns 'standard' email format.
get_from_array([$format])
See get_to_array() function.
$e->get_from_array();
get_reply_to_array([$format])
See get_to_array() function.
$e->get_reply_to_array();
get_sender_array([$format])
See get_to_array() function.
$e->get_sender_array();
get_cc_array([$format])
See get_to_array() function.
$e->get_cc_array();
get_bcc_array([$format])
See get_to_array() function.
$e->get_bcc_array();
get_return_path_array([$format])
See get_to_array() function.
$e->get_return_path_array();
get_size()
Returns the size in bytes of the entire message - including any attachments.
$e->get_size();
get_timestamp()
Returns the UNIX timestamp when the message was sent.
$e->get_timestamp();
get_header_string()
Returns the raw header string - undecoded.
$e->get_header_string();
get_header_array()
Returns the raw, undecoded header fields in a tidy, nested, associative array.
$e->get_header_array();
get_mark_delete()
Returns the delete mark. If the message has been marked to delete, returns TRUE
$e->get_mark_delete();
set_mark_delete($delete)
Mark the message for deletion. You must call expunge() (in the peeker class) in the same connection to actually delete the message after marking it.
$e->set_mark_delete();
$e->expunge();
Detectors - All Return TRUE or FALSE
in_from($from_str)
For string detection in the From header. If the string passed to this function is in the 'From:' header string of the message, return TRUE. Wraps the strpos function and applies it to the undecoded 'From:' header string. This function is case-insensitive.
$e->strpos_from();
in_to($to_str)
For string detection in the To header. If the string passed to this function is in the 'To:' header string of the message, return TRUE. Wraps the strpos function and applies it to the undecoded 'To:' header string.This function is case-insensitive.
$e->strpos_to();
empty_property($property)
Checks the message for data in a property. If the property name (e.g., 'cc') passed to this function is empty, return TRUE.
Here is the list of useful (and potentially empty) properties for a message object: date, subject, message_id, to, from, reply_to, sender, cc, bcc, return_path. This function covers the native properties of the message object. If you need to test whether an arbitrary email message header is empty see the preg_match_header_array_key() detector function below.
$e->empty_property('cc');
is_msgno($msgno)
TRUE if current message's msgno equals the argument $msgno.
$e->is_msgno(1); // check if this is the first message
preg_match_field($arr)
TRUE if the field data matches the regex pattern. Send array with field/property name and pattern. Note: this function only handles the native properties of the message object. If you need to test whether an arbitrary email message header matches a regular expression pattern see the preg_match_header_array_key() detector function below.
$arr = array('To','/spam_magnet/i');
if ($e->preg_match_field($arr)) $e->set_delete();
isset_header_array_key($key)
TRUE if any email header is listed in the email message. Note: header value could be empty.
$e->isset_header_array_key();
preg_match_header_array_key($array)
TRUE if the email header value matches the regular expression. Takes an array as input. Value 1 is the Header name, Value 2 is the regex pattern.
$arr = array('X-Sender','/CodeIgniter/i');
if ($e->preg_match_header_array_key($arr)) $e->undelete();
ttrue($arg)
Call this when you need a function to return TRUE. Useful for declarative programming and testing.
$e->ttrue();
ffalse($arg)
Call this when you need a function to return FALSE. Useful for declarative programming and testing.
$e->ffalse();
reflect($arg)
Call this when you need a function to return the argument you sent it (boolean). Useful for declarative programming and testing.
$e->reflect();
Callback Functions
set_delete($abort=FALSE)
Mark a message for deletion. Note: you must call expunge() in the same connection (usually at the end of the connection and not inside a message acquisition loop) to actually delete the message.
$e->set_delete();
undelete()
If a message has been marked to delete during this connection it will be marked normal again.
$e->undelete();
_print($d)
Convenience function to print data to the screen.
$e->_print();
pr($data)
Print data to the screen using the _print() convenience function.
$e->pr();
print_field($fn)
Print to screen just the value in a message object property.
$e->print_field('date');
print_array($arr)
Print the array in a nice way. Uses 'pre' tags to render the array so it is readable.
$e->print_array();
prepend_subject($prepend_string)
Add a string to the beginning of the subject property. This function changes the data in the message object.
if ($e->in_to('spammagnet')) $e->prepend_subject('SPAM ');
Detector Meta Functions
abort($action_array=FALSE)
Stop running any subsequent detectors. Pass an optional $action_array with a command to run on aborting detectors. The only currently supported command for the action array is 'delete' - pass it as an array (e.g., array('delete'=>TRUE) ).
$e->abort();
abort_if_previous($action_array=FALSE)
If the previous detector method returned TRUE then abort any subsequent detectors. See abort() method for information on the $action_array.
$e->abort_if_previous();
Utility Functions
message_count()
Return the count of messages for the current connection. This is a wrapper function that actually calls the peeker parent class to get the data.
$e->message_count();
log_state($str)
Write a string to the internal peeker log. This is a wrapper function that passes the string to the Peeker parent.
$e->log_state();