function mimemail_address in Mime Mail 6
Same name and namespace in other branches
- 5 mimemail.module \mimemail_address()
- 7 mimemail.inc \mimemail_address()
Helper function to format an address string.
@todo Could use some enhancement and stress testing.
Parameters
$address: A user object, a text email address or an array containing name, mail.
Return value
A formatted address string or FALSE.
2 calls to mimemail_address()
- mimemail_headers in ./
mimemail.inc - Gives useful defaults for standard email headers.
- mimemail_prepare_message in ./
mimemail.module - Default engine's prepare function.
File
- ./
mimemail.inc, line 677 - Common mail functions for sending e-mail. Originally written by Gerhard.
Code
function mimemail_address($address) {
$simple_address = variable_get('mimemail_simple_address', 0);
if (is_array($address)) {
// It's an array containing mail and/or name.
if (isset($address['mail'])) {
$output = '';
if (empty($address['name']) || $simple_address) {
return $address['mail'];
}
else {
return '"' . addslashes(mime_header_encode($address['name'])) . '" <' . $address['mail'] . '>';
}
}
// It's an array of address items.
$addresses = array();
foreach ($address as $a) {
$addresses[] = mimemail_address($a);
}
return $addresses;
}
// It's a user object.
if (is_object($address) && isset($address->mail)) {
if (empty($address->name) || $simple_address) {
return $address->mail;
}
else {
return '"' . addslashes(mime_header_encode($address->name)) . '" <' . $address->mail . '>';
}
}
// Its a formatted or an unformatted string.
// @todo Shouldn't assume it's valid, should try to re-parse.
if (is_string($address)) {
return $address;
}
// It's null, return the site default address.
if (is_null($address)) {
return array(
'name' => mime_header_encode(variable_get('site_name', 'Drupal')),
'mail' => variable_get('site_mail', ini_get('sendmail_from')),
);
}
return FALSE;
}