uTools-Manuals/docs/php/imap_search.html
2019-04-08 23:22:26 +08:00

284 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>This function returns an array of messages matching the given search criteria</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.imap-search" class="refentry">
<div class="refnamediv">
<h1 class="refname">imap_search</h1>
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">imap_search</span> &mdash; <span class="dc-title">This function returns an array of messages matching the given search criteria</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.imap-search-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>imap_search</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$imap_stream</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$criteria</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = SE_FREE</span></span>
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$charset</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
]] ) : <span class="type">array</span></div>
<p class="para rdfs-comment">
This function performs a search on the mailbox currently opened
in the given <acronym title="Internet Message Access Protocol">IMAP</acronym> stream.
</p>
<p class="para">
For example, to match all unanswered messages sent by Mom, you&#039;d
use: &quot;UNANSWERED FROM mom&quot;. Searches appear to be case
insensitive. This list of criteria is from a reading of the UW
c-client source code and may be incomplete or
inaccurate (see also <a href="http://www.faqs.org/rfcs/rfc2060" class="link external">&raquo;&nbsp;RFC2060</a>,
section 6.4.4).
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.imap-search-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">
imap_stream</code></dt>
<dd>
<p class="para"><span class="function"><a href="imap_open.html" class="function">imap_open()</a></span> 返回的 IMAP 流。</p></dd>
<dt>
<code class="parameter">criteria</code></dt>
<dd>
<p class="para">
A string, delimited by spaces, in which the following keywords are
allowed. Any multi-word arguments (e.g.
<em>FROM &quot;joey smith&quot;</em>) must be quoted. Results will match
all <code class="parameter">criteria</code> entries.
<ul class="itemizedlist">
<li class="listitem">
<span class="simpara">
ALL - return all messages matching the rest of the criteria
</span>
</li>
<li class="listitem">
<span class="simpara">
ANSWERED - match messages with the \\ANSWERED flag set
</span>
</li>
<li class="listitem">
<span class="simpara">
BCC &quot;string&quot; - match messages with &quot;string&quot; in the Bcc: field
</span>
</li>
<li class="listitem">
<span class="simpara">
BEFORE &quot;date&quot; - match messages with Date: before &quot;date&quot;
</span>
</li>
<li class="listitem">
<span class="simpara">
BODY &quot;string&quot; - match messages with &quot;string&quot; in the body of the message
</span>
</li>
<li class="listitem">
<span class="simpara">
CC &quot;string&quot; - match messages with &quot;string&quot; in the Cc: field
</span>
</li>
<li class="listitem">
<span class="simpara">
DELETED - match deleted messages
</span>
</li>
<li class="listitem">
<span class="simpara">
FLAGGED - match messages with the \\FLAGGED (sometimes
referred to as Important or Urgent) flag set
</span>
</li>
<li class="listitem">
<span class="simpara">
FROM &quot;string&quot; - match messages with &quot;string&quot; in the From: field
</span>
</li>
<li class="listitem">
<span class="simpara">
KEYWORD &quot;string&quot; - match messages with &quot;string&quot; as a keyword
</span>
</li>
<li class="listitem">
<span class="simpara">
NEW - match new messages
</span>
</li>
<li class="listitem">
<span class="simpara">
OLD - match old messages
</span>
</li>
<li class="listitem">
<span class="simpara">
ON &quot;date&quot; - match messages with Date: matching &quot;date&quot;
</span>
</li>
<li class="listitem">
<span class="simpara">
RECENT - match messages with the \\RECENT flag set
</span>
</li>
<li class="listitem">
<span class="simpara">
SEEN - match messages that have been read (the \\SEEN flag is set)
</span>
</li>
<li class="listitem">
<span class="simpara">
SINCE &quot;date&quot; - match messages with Date: after &quot;date&quot;
</span>
</li>
<li class="listitem">
<span class="simpara">
SUBJECT &quot;string&quot; - match messages with &quot;string&quot; in the Subject:
</span>
</li>
<li class="listitem">
<span class="simpara">
TEXT &quot;string&quot; - match messages with text &quot;string&quot;
</span>
</li>
<li class="listitem">
<span class="simpara">
TO &quot;string&quot; - match messages with &quot;string&quot; in the To:
</span>
</li>
<li class="listitem">
<span class="simpara">
UNANSWERED - match messages that have not been answered
</span>
</li>
<li class="listitem">
<span class="simpara">
UNDELETED - match messages that are not deleted
</span>
</li>
<li class="listitem">
<span class="simpara">
UNFLAGGED - match messages that are not flagged
</span>
</li>
<li class="listitem">
<span class="simpara">
UNKEYWORD &quot;string&quot; - match messages that do not have the
keyword &quot;string&quot;
</span>
</li>
<li class="listitem">
<span class="simpara">
UNSEEN - match messages which have not been read yet
</span>
</li>
</ul>
</p>
</dd>
<dt>
<code class="parameter">options</code></dt>
<dd>
<p class="para">
Valid values for <code class="parameter">options</code> are
<strong><code>SE_UID</code></strong>, which causes the returned array to
contain UIDs instead of messages sequence numbers.
</p>
</dd>
<dt>
<code class="parameter">charset</code></dt>
<dd>
<p class="para">
MIME character set to use when searching strings.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.imap-search-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns an array of message numbers or UIDs.
</p>
<p class="para">
Return <strong><code>FALSE</code></strong> if it does not understand the search
<code class="parameter">criteria</code> or no messages have been found.
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.imap-search-examples">
<h3 class="title">范例</h3>
<div class="example" id="example-4036">
<p><strong>Example #1 <span class="function"><strong>imap_search()</strong></span> example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'{imap.example.com:993/imap/ssl}INBOX'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'foo@example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'pass123'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">OP_READONLY</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$some&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SUBJECT&nbsp;"HOWTO&nbsp;be&nbsp;Awesome"&nbsp;SINCE&nbsp;"8&nbsp;August&nbsp;2008"'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SE_UID</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$msgnos&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ALL'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$uids&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imap_search</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ALL'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SE_UID</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$some</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$msgnos</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$uids</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Array
(
[0] =&gt; 4
[1] =&gt; 6
[2] =&gt; 11
)
Array
(
[0] =&gt; 1
[1] =&gt; 2
[2] =&gt; 3
[3] =&gt; 4
[4] =&gt; 5
[5] =&gt; 6
)
Array
(
[0] =&gt; 1
[1] =&gt; 4
[2] =&gt; 6
[3] =&gt; 8
[4] =&gt; 11
[5] =&gt; 12
)
</pre></div>
</div>
</div>
</div>
<div class="refsect1 seealso" id="refsect1-function.imap-search-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="imap_listscan.html" class="function" rel="rdfs-seeAlso">imap_listscan()</a> - Returns the list of mailboxes that matches the given text</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>