PHP: imap_rfc822_parse_adrlist - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imap_rfc822_parse_headers imap_reopen

Last updated: Sat, 27 Jan 2007

view this page in

# imap_rfc822_parse_adrlist

(PHP 3 >= 3.0.2, PHP 4, PHP 5)

imap_rfc822_parse_adrlist -- Parses an address string

## Описание

array imap_rfc822_parse_adrlist ( string address, string default_host )

Parses the address string as defined in RFC2822 and for each address.

## Список параметров

`address`

  A string containing addresses

`default_host`

  The default host name

## Возвращаемые значения

Returns an array of objects. The objects properties are:

- mailbox - the mailbox name (username)

- host - the host name

- personal - the personal name

- adl - at domain source route

## Примеры

Пример 1. imap_rfc822_parse_adrlist() example

`<?php
$address_string = "Joe Doe <doe@example.com>, postmaster@example.com, root";
$address_array = imap_rfc822_parse_adrlist($address_string, "example.com");
if (!is_array($address_array) || count($address_array) < 1) {
die("something is wrong\n");
}
foreach ($address_array as $id => $val) {
echo "# $id\n";
echo " mailbox : " . $val->mailbox . "\n";
echo " host : " . $val->host . "\n";
echo " personal: " . $val->personal . "\n";
echo " adl : " . $val->adl . "\n";
}
?>`

Результат выполнения данного примера:

    # 0
      mailbox : doe
      host    : example.com
      personal: Joe Doe
      adl     :
    # 1
      mailbox : postmaster
      host    : example.com
      personal:
      adl     :
    # 2
      mailbox : root
      host    : example.com
      personal:
      adl     :

## Смотрите также

imap_rfc822_parse_headers()

add a note User Contributed Notes
imap_rfc822_parse_adrlist
Ian Eiloart
17-Oct-2005 06:50
`This function does NOT test the syntax of either the local part, or the host part, it will permit illegal characters on either side.
Note that 'host' refers to the email domain, not actually to any host.
The at domain list is an obsolete addressing method which was available for routing email. RFC2822 says that it must be accepted, but should be ignored in routing.
Note that if an address doesn't contain a personal part, or an "at domain list", that part of the array will be missing.
Although RFC2822 permits consecutive comma separators in a list of email addresses, this function does not. That's probably a bug.
In the following list of examples, #4 uses an "at domain list", #5 and after are illegal domains, but only the last actually generates an error.
$adds = 'ian eiloart <iane@example.ac.uk>,
shuf6@example.ac.uk,
blobby,
"ian,eiloart"<ian@example.ac.uk>,
<@example.com:foo@example.ac.uk>,
foo@#,
ian@-example.com,
ian@one@two';
$add_arr = imap_rfc822_parse_adrlist($adds, 'example.com');
var_export ($add_arr);
array (
0 =>
class stdClass {
var $mailbox = 'iane';
var $host = 'example.ac.uk';
var $personal = 'ian eiloart';
},
1 =>
class stdClass {
var $mailbox = 'shuf6';
var $host = 'example.ac.uk';
},
2 =>
class stdClass {
var $mailbox = 'blobby';
var $host = 'example.ac.uk';
},
3 =>
class stdClass {
var $mailbox = 'ian';
var $host = 'example.ac.uk';
var $personal = 'ian,eiloart';
},
4 =>
class stdClass {
var $mailbox = 'foo';
var $host = 'example.ac.uk';
var $adl = '@example.com';
},
5 =>
class stdClass {
var $mailbox = 'foo';
var $host = '#';
},
6 =>
class stdClass {
var $mailbox = 'ian';
var $host = '-example.com';
},
7 =>
class stdClass {
var $mailbox = 'ian';
var $host = 'one';
},
8 =>
class stdClass {
var $mailbox = 'UNEXPECTED_DATA_AFTER_ADDRESS';
var $host = '.SYNTAX-ERROR.';
},
)`
Rainer Perske
04-Jan-2005 08:20
`Invalid addresses, if detected, set host to '.SYNTAX-ERROR.'; but not all invalid addresses get detected as such, e.g. <.@host.do.main> is considered
valid though a single dot is not a valid local part without using quotation marks.`
add a note
imap_rfc822_parse_headers imap_reopen

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST