Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 2001

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>imap_open</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="IMAP, POP3 and NNTP Functions"
HREF="ref.imap.html"><LINK
REL="PREVIOUS"
TITLE="imap_num_recent"
HREF="function.imap-num-recent.html"><LINK
REL="NEXT"
TITLE="imap_ping"
HREF="function.imap-ping.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.imap-num-recent.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.imap-ping.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.imap-open"
></A
>imap_open</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN97648"
></A
><P
>    (PHP 3, PHP 4, PHP 5)</P
>imap_open&nbsp;--&nbsp;Open an IMAP stream to a mailbox</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN97651"
></A
><H2
>说明</H2
>resource <B
CLASS="methodname"
>imap_open</B
> ( string mailbox, string username, string password [, int options [, int n_retries]] )<BR
></BR
><P
>&#13;   Opens an IMAP stream to a <CODE
CLASS="parameter"
>mailbox</CODE
>.
  </P
><P
>&#13;   This function can also be used to open streams to POP3 and NNTP servers,
   but some functions and features are only available on IMAP servers.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN97674"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>mailbox</CODE
></DT
><DD
><P
>&#13;       A mailbox name consists of a server and a mailbox path on this server.
       The special name <TT
CLASS="literal"
>INBOX</TT
> stands for the current users
       personal mailbox. Mailbox names that contain international characters
       besides those in the printable ASCII space have to be encoded width
       <A
HREF="function.imap-utf7-encode.html"
><B
CLASS="function"
>imap_utf7_encode()</B
></A
>.
      </P
><P
>&#13;       The server part, which is enclosed in '{' and '}', consists of the servers
       name or ip address, an optional port (prefixed by ':'), and an optional
       protocol specification (prefixed by '/'). 
      </P
><P
>&#13;       The server part is mandatory in all mailbox
       parameters. 
      </P
><P
>&#13;       All names which start with <TT
CLASS="literal"
>{</TT
> are remote names, and are
       in the form <TT
CLASS="literal"
>"{" remote_system_name [":" port] [flags] "}"
       [mailbox_name]</TT
> where:
       <P
></P
><UL
><LI
><P
>&#13;          <TT
CLASS="literal"
>remote_system_name</TT
> - Internet domain name or
          bracketed IP address of server.
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="literal"
>port</TT
> - optional TCP port number, default is the
          default port for that service
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="literal"
>flags</TT
> - optional flags, see following table.
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="literal"
>mailbox_name</TT
> - remote mailbox name, default is INBOX
         </P
></LI
></UL
>
      </P
><P
>&#13;       <DIV
CLASS="table"
><A
NAME="AEN97704"
></A
><P
><B
>表 1. Optional flags for names</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>Flag</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="literal"
>/service=</TT
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>service</I
></SPAN
></TD
><TD
>mailbox access service, default is "imap"</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/user=</TT
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>user</I
></SPAN
></TD
><TD
>remote user name for login on the server</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/authuser=</TT
><SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>user</I
></SPAN
></TD
><TD
>remote authentication user; if specified this is the user name
            whose password is used (e.g. administrator)</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/anonymous</TT
></TD
><TD
>remote access as anonymous user</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/debug</TT
></TD
><TD
>record protocol telemetry in application's debug log</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/secure</TT
></TD
><TD
>do not transmit a plaintext password over the network</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/imap</TT
>, <TT
CLASS="literal"
>/imap2</TT
>,
            <TT
CLASS="literal"
>/imap2bis</TT
>, <TT
CLASS="literal"
>/imap4</TT
>,
            <TT
CLASS="literal"
>/imap4rev1</TT
></TD
><TD
>equivalent to /service=imap</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/pop3</TT
></TD
><TD
>equivalent to /service=pop3</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/nntp</TT
></TD
><TD
>equivalent to /service=nntp</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/norsh</TT
></TD
><TD
>do not use rsh or ssh to establish a preauthenticated IMAP
            session</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/ssl</TT
></TD
><TD
>use the Secure Socket Layer to encrypt the session</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/validate-cert</TT
></TD
><TD
>validate certificates from TLS/SSL server (this is the default
            behavior)</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/novalidate-cert</TT
></TD
><TD
>do not validate certificates from TLS/SSL server, needed if
            server uses self-signed certificates</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/tls</TT
></TD
><TD
>force use of start-TLS to encrypt the session, and reject
            connection to servers that do not support it</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/notls</TT
></TD
><TD
>do not do start-TLS to encrypt the session, even with servers
            that support it</TD
></TR
><TR
><TD
><TT
CLASS="literal"
>/readonly</TT
></TD
><TD
>request read-only mailbox open (IMAP only; ignored on NNTP, and
            an error with SMTP and POP3)</TD
></TR
></TBODY
></TABLE
></DIV
>
      </P
></DD
><DT
><CODE
CLASS="parameter"
>username</CODE
></DT
><DD
><P
>&#13;       The user name
      </P
></DD
><DT
><CODE
CLASS="parameter"
>password</CODE
></DT
><DD
><P
>&#13;       The password associated with the <CODE
CLASS="parameter"
>username</CODE
>
      </P
></DD
><DT
><CODE
CLASS="parameter"
>options</CODE
></DT
><DD
><P
>&#13;       The <CODE
CLASS="parameter"
>options</CODE
> are a bit mask with one or more of
       the following:
       <P
></P
><UL
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_READONLY</B
></TT
> - Open mailbox read-only
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_ANONYMOUS</B
></TT
> - Don't use or update a
          <TT
CLASS="filename"
>.newsrc</TT
> for news (NNTP only)
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_HALFOPEN</B
></TT
> - For IMAP and NNTP names, open a connection but
          don't open a mailbox.
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>CL_EXPUNGE</B
></TT
> - Expunge mailbox automatically upon mailbox close
          (see also <A
HREF="function.imap-delete.html"
><B
CLASS="function"
>imap_delete()</B
></A
> and
          <A
HREF="function.imap-expunge.html"
><B
CLASS="function"
>imap_expunge()</B
></A
>)
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_DEBUG</B
></TT
> - Debug protocol negotiations
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_SHORTCACHE</B
></TT
> - Short (elt-only) caching
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_SILENT</B
></TT
> - Don't pass up events (internal use)
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_PROTOTYPE</B
></TT
> - Return driver prototype
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_EXPUNGE</B
></TT
> - Silently expunge recycle stream
         </P
></LI
><LI
><P
>&#13;          <TT
CLASS="constant"
><B
>OP_SECURE</B
></TT
> - Don't do non-secure authentication
         </P
></LI
></UL
>
      </P
></DD
><DT
><CODE
CLASS="parameter"
>n_retries</CODE
></DT
><DD
><P
>&#13;       Number of maximum connect attempts
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN97839"
></A
><H2
>返回值</H2
><P
>&#13;   Returns an IMAP stream on success or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on error.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN97843"
></A
><H2
>更新日志</H2
><P
>&#13;   <DIV
CLASS="informaltable"
><P
></P
><A
NAME="AEN97846"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>版本</TH
><TH
>说明</TH
></TR
></THEAD
><TBODY
><TR
><TD
>5.2.0</TD
><TD
><CODE
CLASS="parameter"
>n_retries</CODE
> added</TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN97857"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN97860"
></A
><P
><B
>例 1. Different use of <B
CLASS="function"
>imap_open()</B
></B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// To connect to an IMAP server running on port 143 on the local machine,<br />// do the following:<br /></font><font color="#0000BB">$mbox </font><font color="#007700">= </font><font color="#0000BB">imap_open</font><font color="#007700">(</font><font color="#DD0000">"{localhost:143}INBOX"</font><font color="#007700">, </font><font color="#DD0000">"user_id"</font><font color="#007700">, </font><font color="#DD0000">"password"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// To connect to a POP3 server on port 110 on the local server, use:<br /></font><font color="#0000BB">$mbox </font><font color="#007700">= </font><font color="#0000BB">imap_open </font><font color="#007700">(</font><font color="#DD0000">"{localhost:110/pop3}INBOX"</font><font color="#007700">, </font><font color="#DD0000">"user_id"</font><font color="#007700">, </font><font color="#DD0000">"password"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// To connect to an SSL IMAP or POP3 server, add /ssl after the protocol<br />// specification:<br /></font><font color="#0000BB">$mbox </font><font color="#007700">= </font><font color="#0000BB">imap_open </font><font color="#007700">(</font><font color="#DD0000">"{localhost:993/imap/ssl}INBOX"</font><font color="#007700">, </font><font color="#DD0000">"user_id"</font><font color="#007700">, </font><font color="#DD0000">"password"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// To connect to an SSL IMAP or POP3 server with a self-signed certificate,<br />// add /ssl/novalidate-cert after the protocol specification:<br /></font><font color="#0000BB">$mbox </font><font color="#007700">= </font><font color="#0000BB">imap_open </font><font color="#007700">(</font><font color="#DD0000">"{localhost:995/pop3/ssl/novalidate-cert}"</font><font color="#007700">, </font><font color="#DD0000">"user_id"</font><font color="#007700">, </font><font color="#DD0000">"password"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// To connect to an NNTP server on port 119 on the local server, use:<br /></font><font color="#0000BB">$nntp </font><font color="#007700">= </font><font color="#0000BB">imap_open </font><font color="#007700">(</font><font color="#DD0000">"{localhost:119/nntp}comp.test"</font><font color="#007700">, </font><font color="#DD0000">""</font><font color="#007700">, </font><font color="#DD0000">""</font><font color="#007700">);<br /></font><font color="#FF8000">// To connect to a remote server replace "localhost" with the name or the<br />// IP address of the server you want to connect to.<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN97864"
></A
><P
><B
>例 2. <B
CLASS="function"
>imap_open()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$mbox </font><font color="#007700">= </font><font color="#0000BB">imap_open</font><font color="#007700">(</font><font color="#DD0000">"{imap.example.org:143}"</font><font color="#007700">, </font><font color="#DD0000">"username"</font><font color="#007700">, </font><font color="#DD0000">"password"</font><font color="#007700">);<br /><br />echo </font><font color="#DD0000">"&lt;h1&gt;Mailboxes&lt;/h1&gt;\n"</font><font color="#007700">;<br /></font><font color="#0000BB">$folders </font><font color="#007700">= </font><font color="#0000BB">imap_listmailbox</font><font color="#007700">(</font><font color="#0000BB">$mbox</font><font color="#007700">, </font><font color="#DD0000">"{imap.example.org:143}"</font><font color="#007700">, </font><font color="#DD0000">"*"</font><font color="#007700">);<br /><br />if (</font><font color="#0000BB">$folders </font><font color="#007700">== </font><font color="#0000BB">false</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Call failed&lt;br /&gt;\n"</font><font color="#007700">;<br />} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach (</font><font color="#0000BB">$folders </font><font color="#007700">as </font><font color="#0000BB">$val</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">$val </font><font color="#007700">. </font><font color="#DD0000">"&lt;br /&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br />echo </font><font color="#DD0000">"&lt;h1&gt;Headers in INBOX&lt;/h1&gt;\n"</font><font color="#007700">;<br /></font><font color="#0000BB">$headers </font><font color="#007700">= </font><font color="#0000BB">imap_headers</font><font color="#007700">(</font><font color="#0000BB">$mbox</font><font color="#007700">);<br /><br />if (</font><font color="#0000BB">$headers </font><font color="#007700">== </font><font color="#0000BB">false</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Call failed&lt;br /&gt;\n"</font><font color="#007700">;<br />} else {<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach (</font><font color="#0000BB">$headers </font><font color="#007700">as </font><font color="#0000BB">$val</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">$val </font><font color="#007700">. </font><font color="#DD0000">"&lt;br /&gt;\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></font><font color="#0000BB">imap_close</font><font color="#007700">(</font><font color="#0000BB">$mbox</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN97868"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.imap-close.html"
><B
CLASS="function"
>imap_close()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.imap-num-recent.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.imap-ping.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>imap_num_recent</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.imap.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>imap_ping</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>