©
本文档使用
php.cn手册 发布
This extension requires the c-client library to be installed. Grab the latest version from » ftp://ftp.cac.washington.edu/imap/ and compile it.
It's important that you do not copy the IMAP source files directly into the system include directory as there may be conflicts. Instead, create a new directory inside the system include directory, such as /usr/local/imap-2000b/ (location and name depend on your setup and IMAP version), and inside this new directory create additional directories named lib/ and include/. From the c-client directory from your IMAP source tree, copy all the *.h files into include/ and all the *.c files into lib/. Additionally when you compiled IMAP, a file named c-client.a was created. Also put this in the lib/ directory but rename it as libc-client.a.
Note:
To build the c-client library with SSL or/and Kerberos support read the docs supplied with the package.
Note: In Mandrake Linux, the IMAP library (libc-client.a) is compiled without Kerberos support. A separate version with SSL (client-PHP4.a) is installed. The library must be recompiled in order to add Kerberos support.
[#1] jameslandrok at gmail dot com [2015-01-27 17:32:29]
A more secure & easy way to do this on Debian 7.7, php 5.4:
apt-get install php5-imap
Packages installed
libc-client2007e mlock php5-imap
[#2] crabb1d at gmail dot com [2013-09-09 15:02:01]
For those using Ubuntu and who are completely daunted by compiling this, it's easy under Ubuntu:
Install libc-client-dev
# sudo apt-get install libc-client-dev
Install PHP5 imap:
# sudo apt-get install php5-imap
Restart Apache
# sudo service apache2 reload
Should work for most people.
[#3] Anonymous [2013-07-19 22:04:40]
When compiling IMAP 2007f with php 5.3.27 on a 64 bit OL5.7 machine, add in the Makefile: EXTRACFLAGS=-fPIC and EXTRAAUTHENTICATORS=gss
[#4] Anonymous [2011-10-04 10:58:07]
When compiling IMAP on a 64 bit machine, use: make EXTRACFLAGS=-fPIC.
[#5] ldi at email dot cz [2010-08-04 10:09:21]
After few hours of testing it on CentOS 5 64 bit I'd like to share the steps required to compile imap with php:
1. Install openssl:
yum install openssl openssl-devel
2. If you don't have openssl compiled and installed in /usr/local/ssl create symlink:
ln -s /usr/lib64/openssl/engines/ /usr/local/ssl
3. Add the libraries:
ln -s /usr/include/ /usr/local/ssl/include
4. Compile IMAP
cd /path/to/imap_src
make lnp SSLTYPE=unix
5. Copy files as described above
mkdir lib
mkdir include
cp c-client*
private function encodeHeader($input, $charset = 'ISO-8859-1')
{
preg_match_all('/(\s?\w*[\x80-\xFF]+\w*\s?)/', $input, $matches);
foreach ($matches[1] as $value) {
$replacement = preg_replace('/([\x20\x80-\xFF])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
$input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
}
return wordwrap($input,75,"\n\t",true);
}
?>
[#8] hans at lintoo dot dk [2005-10-04 10:35:04]
I modified nick at plumdigitalmedia dot com's note so that it may support ISO-8859-1 encoded headers:
<?php
public function encodeSubject($string,$prefix="=?ISO-8859-1?Q?",$postfix="?=") {
$crlf = "\n\t";
$string = preg_replace('!(\r\n|\r|\n)!', $crlf, $string) . $crlf ;
$f[] = '/([\000-\010\013\014\016-\037\075\177-\377])/e' ;
$r[] = "'=' . sprintf('%02X', ord('\\1'))" ;
$f[] = '/([\011\040])' . $crlf . '/e' ;
$r[] = "'=' . sprintf('%02X', ord('\\1')) . '" . $crlf . "'" ;
$string = preg_replace($f, $r, $string);
return $prefix.trim(wordwrap($string, 70 - strlen($prefix) - strlen($postfix), ' ' . $postfix . $crlf . $prefix, true)).$postfix;
}
?>
Regards, Hans @ http://lintoo.dk/
[#9] marco dot manngatter at ecg-leipzig dot de [2005-09-15 03:43:12]
you can use the following to make a larger subject.
use the imap_qprint() function, to convert your subject.
example:
<?php
$subject .= "=?iso-8859-1?Q?" . imap_qprint($subject) . "?=";
?>
[#10] nick at plumdigitalmedia dot com [2005-05-10 08:15:11]
This function appears to wrap lines in the middle of words, not just at whitespace, which upsets some versions of Outlook Express when used to format email body text. We've had more luck with this function:
<?php
function quoted_printable($string)
{
$crlf = "\n" ;
$string = preg_replace('!(\r\n|\r|\n)!', $crlf, $string) . $crlf ;
$f[] = '/([\000-\010\013\014\016-\037\075\177-\377])/e' ;
$r[] = "'=' . sprintf('%02X', ord('\\1'))" ;
$f[] = '/([\011\040])' . $crlf . '/e' ;
$r[] = "'=' . sprintf('%02X', ord('\\1')) . '" . $crlf . "'" ;
$string = preg_replace($f, $r, $string) ;
return trim(wordwrap($string, 70, ' =' . $crlf)) ;
}
?>
[#11] k dot kozlowski at enter dot pl [2005-03-14 06:50:39]
I had problems with encoding large subjects with polish characters. The problem was that imap_8bit() splits subject (on 75-th char) but when I add "=?ISO-8859-2?Q?" the header is too long.
This is a solution :
<?php
$subject = str_replace(" ", "_", trim($subject)) ;
// We need to delete "=\r\n" produced by imap_8bit() and replace '?'
$subject = str_replace("?", "=3F", str_replace("=\r\n", "", imap_8bit($subject))) ;
// Now we split by \r\n but with encoding text "=?ISO ..."
$subject = str_replace("\r\n", "?=\r\n =?ISO-8859-2?Q?", chunk_split($subject, 55)) ;
// We also have to remove last unneeded encoding text :
$subject = "=?ISO-8859-2?Q?" . substr($subject, 0, strlen($subject)-20) . "?=" ;
?>
[#12] rayFX [2004-06-24 09:14:50]
imap_8bit seems to have a bug as it doesn't encode "?".
Had a lot of trouble to encode a mail-subject with
german umlaute with an ending "?"...
Try this:
$subject = "=?iso-8859-1?Q?" . str_replace("?","=3F",imap_8bit($tsubject_to_encode)) . "?=";
[#13] MagicalTux at FF.ST [2003-12-15 06:50:03]
Reading Bully's note :
you can use the following to make a larger subject:
<?php
$encoded = str_replace("=\r\n","",imap_8bit($string_to_encode));
?>
It's wrong. The header MAY NOT go over 75 chars per line.
The right solution :
<?php
$encoded = rtrim( str_replace( "\n","\n\t", imap_8bit ($string_to_encode)))."\r\n";
?>
It will add \t at the start of the encoded new lines.
Mailers to see the lines after Subject: as extensions of this header.
[#14] php dot net at werner-ott dot de [2002-12-09 14:45:41]
A comment on the "split-after-75-characters" phenomenon:
By splitting lines up after 75 characters, the function's behaviour is complying to RFC2047 (http://www.ietf.org/rfc/rfc2047.txt) (which specifies a protocol for the representation of non-ASCII text in message headers), section "2. Syntax of encoded-words".
A so called 'encoded word' has the following format:
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
An 'encoded-word' may not be more than 75 characters long, including 'charset', 'encoding', 'encoded-text', and delimiters. If it is desirable to encode more text than will fit in an 'encoded-word' of 75 characters, multiple 'encoded-word's (separated by CRLF SPACE) may be used.
hth
WOT
[#15] bully at newearth dot de [2002-04-24 07:48:30]
you can use the following to make a larger subject:
$encoded = str_replace("=\r\n","",imap_8bit($string_to_encode));
[#16] zuffa at isdd dot sk [2000-09-23 20:57:15]
Warning !
This function splits input text into
several lines aligned to 75 characters.
This is critical when you need input
text to be only one striaght line as
e.g. in e-mail header values.