|
|
 |
LIV. IMAP, POP3 and NNTP Functions
These functions are not limited to the IMAP protocol,
despite their name. The underlying c-client library also supports
NNTP, POP3 and local mailbox access
methods.
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.
To get these functions to work, you have to compile PHP with
--with-imap[=DIR], where DIR is the
c-client install prefix. From our example above, you would use
--with-imap=/usr/local/imap-2000b.
This location depends on where you created this directory according to the
description above. Windows users may include the
php_imap.dll DLL in php.ini.
IMAP is not supported on systems earlier that Windows 2000. This is because it
uses encryption functions in order to enable SSL connections to the mail
servers.
Note:
Depending how the c-client was configured, you might also need to add
--with-imap-ssl=/path/to/openssl/
and/or --with-kerberos=/path/to/kerberos
into the PHP configure line.
| Warning | The IMAP extension cannot be used in conjuction with
the recode, YAZ or Cyrus extensions. This is due to the fact that they
both share the same internal symbol. |
This extension has no configuration directives defined in php.ini.
The constants below are defined by this extension, and
will only be available when the extension has either
been compiled into PHP or dynamically loaded at runtime.
This document can't go into detail on all the topics touched by
the provided functions. Further information is provided by the
documentation of the c-client library source
(docs/internal.txt). and the following RFC
documents:
RFC2821: Simple Mail
Transfer Protocol (SMTP).
RFC2822: Standard for
ARPA internet text messages.
RFC2060: Internet
Message Access Protocol (IMAP) Version 4rev1.
RFC1939: Post
Office Protocol Version 3 (POP3).
RFC977: Network News
Transfer Protocol (NNTP).
RFC2076: Common
Internet Message Headers.
RFC2045 , RFC2046 , RFC2047 , RFC2048 & RFC2049: Multipurpose
Internet Mail Extensions (MIME).
A detailed overview is also available in the books
Programming Internet Email
by David Wood and Managing
IMAP by Dianna Mullet & Kevin Mullet.
User Contributed Notes
IMAP, POP3 and NNTP Functions
Anonymous
13-Apr-2005 03:13
If you are having difficulty compiling on netbsd from source and want imap support then you should know that the c-client library is compiled with kerberos support. Unfortunately gssapi_krb5 and k5crypto is not on the system (or at least wasn't for me). I didn't have administrative level access to add these libraries so I had to do the following. I still have to test that it worked 100% but at least it compiled without complaining.
Comment the following segments from the configure script.
Segment 1 -- test for gssapi_krb5 library
case gssapi_krb5 in
c|c_r|pthread*) ;;
*)
if test "$ext_shared" = "yes"; then
IMAP_SHARED_LIBADD="$IMAP_SHARED_LIBADD -lgssapi_krb5"
else
case gssapi_krb5 in
c|c_r|pthread*) ;;
*)
LIBS="$LIBS -lgssapi_krb5"
;;
esac
fi
;;
esac
Segment 2 -- test for k5crypto
case k5crypto in
c|c_r|pthread*) ;;
*)
if test "$ext_shared" = "yes"; then
IMAP_SHARED_LIBADD="$IMAP_SHARED_LIBADD -lk5crypto"
else
case k5crypto in
c|c_r|pthread*) ;;
*)
LIBS="$LIBS -lk5crypto"
;;
esac
fi
;;
esac
BTW. Since I was only compiling for the modules (they have suPHP so I compile all my own modules when I need them) I only dropped this in for the php configure script parameters
./configure --with-imap=shared,xxxxxx --with-kerberos=xxxxxx --with-imap-ssl
This is verified working via an imap test. One excellent test that I located on the phpbuilder.com site. Here it is. Modify the address, port, protocol type, username, and password appropriately. The post was 5 years old but the script still works fine. The posters name was "Matthew"
<HTML>
<HEAD>
<TITLE>imap_check</TITLE>
</HEAD>
<BODY>
<?
$mailbox = imap_open("{localhost/pop3:110}INBOX",
"#username#","#password#");
$check = imap_check($mailbox);
print("<PRE>");
print("Date most recent message : " . $check->Date);
print("<BR>");
print("Connection type : " . $check->Driver);
print("<BR>");
print("Name of the mailbox : " . $check->Mailbox);
print("<BR>");
print("Number of messages : " . $check->Nmsgs);
print("<BR>");
print("Number of recent messages : " . $check->Recent);
print("<BR>");
print("</PRE>");
$index=1;
$header = imap_header($mailbox, $index);
print("<PRE>");
print("Header Date : " . $header->Date . "<BR>");
print("Header To : " . $header->to) . "<BR>";
print("Header From : " . $header->From . "<BR>");
print("Header cc : " . $header->cc . "<BR>");
print("Header ReplyTo : " . $header->ReplyTo . "<BR>");
print("Header Subject : " . $header->Subject . "<BR></PRE>");
print("<PRE>");
print(imap_body($mailbox,$index));
print("</PRE><HR>");
imap_close($mailbox);
?>
</BODY></HTML>
seem dot iges at mail dot ee
15-Feb-2005 08:48
If you like me disvoer that "make slx" fails, but you're damn sure you've openssl installed then, it might be that the lib and include paths on your distro are different then the defaults provided in the imap-2004a (or imap-XXXXx). To modify go to dir ../imap-2004a/src/osdep/unix and edit the section (shown below) in the Makefile
# Extended flags needed for SSL. You may need to modify.
#SSLDIR=/usr/local/ssl
SSLDIR=/etc/ssl
SSLCERTS=$(SSLDIR)/certs
SSLKEYS=$(SSLCERTS)
#SSLINCLUDE=$(SSLDIR)/include
SSLINCLUDE=/usr/include/openssl
#SSLLIB=$(SSLDIR)/lib
SSLLIB=/usr/lib
SSLCRYPTO=-lcrypto
Commented out SSLDIR, SSLINCLUDE and SSLIB are defaults and the uncommented are valid paths for Slackware (10.0/10.1).
You should also check your ld.so.conf for valid paths.
antivert
13-Jan-2005 11:55
Note that is not not necessary to disable SSL in the IMAP compile to make it work with PHP 5.0.3.
1. Compile IMAP with SSL support for your system:
cd /path/to/imap/source/
make <system type> (ldb, lnx, etc)
mkdir include
mkdir lib
2. Make links in IMAP source directory:
cd /path/to/imap/source/c-client
cp *.h ../include/
cp *.c ../lib/
cp c-client.a ../lib/libc-client.a
3. Compile PHP with SSL support, --with-imap=/path/to/imap/source/ . If SSL support fails, you'll get a configure-time error that IMAP doesn't work. This is a lie, you just need to get SSL support working in PHP. On certain linux systems, with OpenSSL 0.9.7, this means adding --with-openssl=/usr (if the OpenSSL files are in /usr/include/openssl/) instead of the proper directory containing the OpenSSL files. For some reason, giving a parent directory makes PHP able to find the OpenSSL include files.
4. PHP should build.
Alternately, you can disable SSL during the IMAP build, as per the previous directions posted here.
amit dot gupta at prudence-india dot com
18-Nov-2004 03:44
I faced problem in compiling imap with php-5.0.2 release version. Then following commands on snapshot version solved my problem
# tar -zxvf imap-2004b.DEV.tar.Z
# cd imap-2004b.DEV.SNAP-0411051435/
# make lnp SSLTYPE=none
# cp -r /usr/local/imap-2004b.DEV.SNAP-0411051435/c-client/*.h /usr/local/imap-2004b.DEV.SNAP-0411051435/include/
# cp -r /usr/local/imap-2004b.DEV.SNAP-0411051435/c-client/*.c /usr/local/imap-2004b.DEV.SNAP-0411051435/lib/
# ln -s /usr/local/imap-2004b.DEV.SNAP-0411051435/c-client/c-client.a /usr/local/imap-2004b.DEV.SNAP-0411051435/lib/libc-client.a
# tar -zxvf php5-STABLE-200411180530.tar.gz
# cd php5-STABLE-200411180530
./configure --with-apxs2=/usr/sbin/apxs --enable-shared --with-mod_charset --enable-force-cgi-redirect --enable-fastcgi --enable-magic-quotes --with-openssl --with-zlib --enable-bcmath --enable-calendar --with-curl --with-curlwrappers --enable-dba --with-gdbm --with-cdb --with-inifile --with-flatfile --enable-dbase --enable-dbx --enable-dio --with-fam --enable-filepro --enable-ftp --with-ldap --enable-mbstring --with-mysql=/usr/include --with-zlib-dir --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-pic --enable-versioning --with-pgsql --with-java=/usr/java/jdk1.5.0/ --with-imap=/usr/local/imap-2004b.DEV.SNAP-0411051435 --with-kerberos
# make
# make install
Thus, php compiled sucessufully with imap support on fedora core 1.
sirber at gmail dot com
17-Nov-2004 01:42
Here's a function to create a full structure with decoded bodies. Usefull for handeling complex MIME messages.
// Construction de la structure du message
$struct = imap_fetchstructure($mbox, $mnum);
// Recherche des body et décodage de la structure
buildparts($mbox, $mnum, $struct);
function buildparts ($mbox, $mnum, &$struct, $pno = "")
{
switch ($struct->type)
{
case 1: // multipart
// Recherche des sous partie
$i = 1;
while (list($j) = each ($struct->parts))
buildparts ($mbox, $mnum, $struct->parts[$j], $pno . "." . $i++);
break;
case 2: // message
// Décodage de la sous partie (et de ses sous parties)
buildparts ($mbox, $mnum, $struct->parts[0], $pno);
break;
default:
$part = substr ($pno, 1);
// On save le part_number
$struct->part_number = $part;
// On fetch le body de la partie
$struct->body = imap_fetchbody($mbox, $mnum, $part);
// On le décode
if($struct->encoding == 3)
$struct->body = imap_base64($struct->body);
elseif($struct->encoding == 4)
$struct->body = imap_qprint($struct->body);
// On décode les charset
if ($struct->paraneters[0]->attribute == "CHARSET")
{
$charset = $struct->paraneters[0]->value;
if ($charset == "utf-8")
$struct->body = utf8_decode($struct->body);
if ($charset == "utf-7")
$struct->body = imap_utf7_decode($struct->body);
}
break;
}
}
Pete Spicer, sleeping [at] myperch.org
17-Jul-2004 06:19
I have a pretty much stock set-up of SuSE 8.1 Personal (Apache, PHP et al built by me) and IMAP-2004 refused to build for me.
What I found was, using the make lsu (for SuSE) almost worked built I was getting odd build results, i.e. make failures.
The problem? GCC 3.2. If you don't have an older GCC available, please install one! I installed the gcc_old package from SuSE and built with the following command:
CC=gcc297 make lsu SSLTYPE=none
The result was a perfect build. So if you are getting errors, please try an earlier build of GCC.
Tomas V.V.Cox
11-May-2004 09:15
For compiling this extension without compiling imap from sources I did (this was mandrake):
Install the following rpms:
imap
imap-devel
openssl
openssl-devel
krb5
krb5-devel
pam
pam-devel
Do the trick:
# mkdir /usr/include/imap/lib
# cp /usr/lib/libc-client-PHP4.a /usr/include/imap/lib/libc-client.a
And the configure line:
./configure <options> --with-imap=/usr/include/imap --with-imap-ssl
(don't forget --enable-pear ;)
sysadmin at grmtech dot com
27-Mar-2004 07:01
The manual mentions:
"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.
"
A. Please do not copy rather make symbolic links like this:
ln -s c-client include
ln -s c-client lib
B. You do not need to copy c-client.a to libc-client.a.
The make command used to compile the imap-2002e source code creates the symbolic link from c-client.a to libc-client.a
The imap client version used for the above two points is:
1. imap-2002e
my 2 cents,
sysadmin
http://www.grmtech.com
peder at godvik dot no
09-Mar-2004 11:24
Additionally to Mauricio's procedure; You must check the Makefile to find the correct system type that you are compiling on. Mauricio's example assumes you are using Linux. -Check the README for imap-xxxx for further details.
Fjor
14-Feb-2004 08:50
Additionally to Mauricio's procedure, I had to make a symlink to the c-client library this way:
cd imap-xxxx/c-client
ln -s c-client.a libc-client.a
(Tested with imap-200e)
Fjor (GDL/Mexico)
dev at puertocity dot com
26-Nov-2003 11:38
A tip for imap support installation:
With SSL support:
------------------
tar -zxf imap-xxxxx.tar.Z
cd imap-xxxxx
make slx
ln -sf c-client include
ln -sf c-client lib
cd ..
tar -jxf php-4.3.x.tar.bz2
cd php-4.3.x
./configure --with-imap=../imap-xxxxx --with-imap-ssl=/path-to-openssl
With out SSL support:
---------------------
tar -zxf imap-xxxxx.tar.Z
cd imap-xxxxx
make slx SSLTYPE=none
ln -sf c-client include
ln -sf c-client lib
cd ..
tar -jxf php-4.3.x.tar.bz2
cd php-4.3.x
./configure --with-imap=../imap-xxxxx
Good Luck
Mauricio
millz at incogen dot com
10-Oct-2003 07:19
I experienced a problem when adding IMAP support into PHP. The php configure script would die when trying to see if "IMAP Works..." and the config.log would complain about libc-client.a references.
It was similar to the problem reported here:
http://lists.horde.org/archives/imp/Week-of-Mon-20030915/034692.html
I resolved it by compiling IMAP like this (replace <ARCH> with the proper OS type for your system, get that from the top of the Makefile):
make <ARCH> SSLTYPE=none
That turned off the SSL support in the IMAP files and seemed to resolve my php compile problem.
BTW, I also followed the directions about making a new /usr/local/imap... directory that are mentioned at the top of the page.
k3nny at squidart dot co dot za
31-Jul-2003 08:02
After having numerous problems compiling PHP with IMAP support, both PHP problems and IMAP problems I found this simple solution to the problem, which I've tried with several versions of IMAP and all worked perfectly!
tar -zxf imap-xxxxx.tar.Z
cd imap-xxxxx
make slx
ln -sf c-client include
ln -sf c-client lib
cd ..
tar -jxf php-4.3.x.tar.bz2
cd php-4.3.x
./configure --with-imap=../imap-xxxxx
It worked everytime for me, hope it does for you!
Kenneth
designer at bs-dee dot org
09-Mar-2003 07:27
keeper at odi dot com dot br
01-Mar-2003 03:37
naveed at php dot net
12-Jan-2003 10:49
Beware!
If you are trying to make a connection with POP3 mailbox,then some of IMAP functions will not work correctly as you might expecting .This is because the difference of workings in POP3 and IMAP protocols.
These functions work correctly for IMAP mailboxes but some of the fnctions will return nothing, when connected to a POP3 mailbox.(even no error message).
duckel at electroporn dot de
22-May-2002 02:16
please don't copy the .h files in the system include directory! the unix.h file from the washington.edu c-client conflicts with another file called unix.h
make a dir called "imap" in either /usr/include or /usr/local/include or whatever you wish, copy the header files there and the .a file prefix'ish in /usr/lib or /usr/local/lib or whatever you used for the include files.
then tell configure with --with-imap=/usr the "prefix" of your installation.
then works without problem ;)
netshadow at madpoets dot org
03-Nov-2001 04:42
I just found something a bit bizarre. I was having problems with the pages taking too long to load (15-20sec) when they opened an imap connection. I was pulling my hair out trying to figure out what was wrong.
Turns out it was quite simple. I was letting it default to 143 for the port. When i specified the port number (i.e. {localhost:143} rather than {localhost} ) It reduced page load time to a few seconds.
raoul at runtheotherway dot com
22-Oct-2001 10:11
I have found the order in which you connect to you POP server with IMAP 2000 and your database with PostgreSQL 7.1.2 can cause problems.
Make sure that you connect first to your POP server then get your db connection. This will prevent you from getting an invalid stream from imap_open().
| |