From 7e6ab105a578f3cf4ddf63bf16bb44cb40daeb41 Mon Sep 17 00:00:00 2001 From: Jyhere Date: Wed, 20 Sep 2023 13:11:23 +0200 Subject: [PATCH] FIX: If PHPIMAP is active, recordjoinpiece operation won't work --- .../class/emailcollector.class.php | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index a12411c09e2..f808caf4e1d 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -1735,7 +1735,6 @@ class EmailCollector extends CommonObject $overview[0]->subject = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $overview[0]->subject); } // GET IMAP email structure/content - global $htmlmsg, $plainmsg, $charset, $attachments; if (!empty($conf->global->MAIN_IMAP_USE_PHPIMAP)) { @@ -2606,15 +2605,25 @@ class EmailCollector extends CommonObject } } } elseif ($operation['type'] == 'recordjoinpiece') { - $pj = getAttachments($imapemail, $connection); - foreach ($pj as $key => $val) { - $data[$val['filename']] = getFileData($imapemail, $val['pos'], $val['type'], $connection); + $data = []; + if (!empty($conf->global->MAIN_IMAP_USE_PHPIMAP)) { + foreach ($attachments as $attachment) { + if ($attachment->getName() === 'undefined') { + continue; + } + $data[$attachment->getName()] = $attachment->getContent(); + } + } else { + $pj = getAttachments($imapemail, $connection); + foreach ($pj as $key => $val) { + $data[$val['filename']] = getFileData($imapemail, $val['pos'], $val['type'], $connection); + } } - if (count($pj) > 0) { + if (count($data) > 0) { $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."user WHERE email LIKE '%".$this->db->escape($from)."%'"; $resql = $this->db->query($sql); if ($this->db->num_rows($resql) == 0) { - $this->errors[] = 'User Not allowed to add documents'; + $this->errors[] = "User Not allowed to add documents ({$from})"; } $arrayobject = array( 'propale' => array('table' => 'propal', @@ -2757,9 +2766,8 @@ class EmailCollector extends CommonObject } } foreach ($dirs as $target) { + $prefix = $this->actions[$this->id]['actionparam']; foreach ($data as $filename => $content) { - $prefix = $this->actions[$this->id]['actionparam']; - $resr = saveAttachment($target, $prefix . '_' . $filename, $content); if ($resr == -1) { $this->errors[] = 'Doc not saved';