Source for file imapfunc.php
Documentation is available at imapfunc.php
* Fichier de fonction IMAP
* LODEL - Logiciel d'Edition ELectronique.
* Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
* Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
* Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
* Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* Home page: http://www.lodel.org
* E-Mail: lodel@lodel.org
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* @author Ghislain Picard
* @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
* @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
* @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
* @licence http://www.gnu.org/copyleft/gpl.html
* Retire les pièces jointes des mails sur une boîte mail donnée
* Cette fonction utilise les options lodelmail.host, lodelmail.user, lodelmail.passwd.
* @return le nombre de pièces jointes
$options = getoption(array ("lodelmail.host", "lodelmail.user", "lodelmail.passwd"), "");
if (count($options) != 3 || !$options['lodelmail.host']) {
die('ERROR: To use this feature, you must create and fill the options host, user and passwd in the group lodelmail. See in the administration interface ');
list ($host, $port) = explode(":", $options['lodelmail.host']);
$mailserver = "{". $host. ":". ($port ? $port : "110"). "/pop3}INBOX";
$passwd = $options['lodelmail.passwd'];
$user = $options['lodelmail.user'];
$mbox = imap_open($mailserver, $user, $passwd);
$nbmsg = imap_num_msg($mbox);
for ($msgno = 1; $msgno <= $nbmsg; $msgno ++ ) {
$nbattachment += extractattachments($mbox, $msgno, "(je?pg|png|gif|tiff|sxw|doc|rtf|html?)");
imap_delete($mbox, $msgno);
* Extrait les pièces jointes des mails d'une boîte donnée
* @param object $mbox la boîte mail
* @param integer $mnum le numéro du mail
* @param string $extre extension acceptées
* @param integer $struct par défaut 0.la structure des pièces jointes
* @param integer $pno par défaut vide la partie des attachements (cas des mails multiparts)
$struct = imap_fetchstructure($mbox, $mnum);
while (list ($j) = each($struct->parts)) {
$nbattachment += extractattachments($mbox, $mnum, $extre, $struct->parts[$j], $pno. $partno);
// fetch the body of the part
$body = imap_fetchbody($mbox, $mnum, $pno);
if ($struct->encoding == 3) {
$body = imap_base64($body);
elseif ($struct->encoding == 4) {
$body = imap_qprint($body);
if ($struct->parameters[0]->attribute == "NAME") {
$filename = $struct->parameters[0]->value;
return; // no filename don't download
$ext = substr($filename, $extpos);
// check the extension is valid
if (strlen($filename) > 127) { // limit the length of the filename
// save the attachment as $filename
|