By Anna on Thursday, 03 March 2016
Posted in Technical Issues
Likes 0
Views 481
Votes 0
Hi,

when trying to attach a pdf file to a question when using the email parser mail in functionality it does not work. PDF is not attached - only the text of the article is posted. If using JPG or GIF attachments they are included in the article.

Attaching of the same PDF File within the webfrontend is working without any problems.

Anything we could do?

KR,

Anna
Hey Anna,

Unfortunately that was not possible retrieve PDF, ZIP, Word or Excel file from email to Easydiscuss system yet.

Because different email provider also have their own form of secure email with encrypted for PDF, ZIP, Word or Excel format. In other word, the email attachment is a password protected file, currently we do not know how to retrieve these email attachment (PDF, ZIP, Word or Excel) password from different email provider in PHP.

Now only available for the image when post via email e.g. 'jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG'.
·
Thursday, 03 March 2016 16:32
·
0 Likes
·
0 Votes
·
0 Comments
·
ok, thanks.
·
Thursday, 03 March 2016 16:48
·
0 Likes
·
0 Votes
·
0 Comments
·
You're welcome.
·
Thursday, 03 March 2016 17:13
·
0 Likes
·
0 Votes
·
0 Comments
·
Fixed it for our own use and is working.

in DiscussMailerMessage->extractPart method added:

    /*
* Application
*/
elseif ($type == 3)
{
$application = array();
$application['mime'] = $subtype; // PDF
$application['data'] = $data; // binary
$application['name'] = isset($params['name']) ? $params['name'] : $params['filename']; //
$application['id'] = $id;
$application['size'] = $part->bytes;
$application['type'] = 3;
$this->attachment[] = $application;
}


and in DMMailQueue->processEmails method changed:
$imgExts        = array( 'jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG' );

to
$imgExts        = array( 'jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG', 'pdf', 'PDF' );

as a workaround.

In my opinion it would be better to check the MIME type instead of checking the extension, hence I added the "type" to the attachment array. for my future use if necessary.
·
Friday, 04 March 2016 01:05
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for sharing again

We will see if we can include this in the future release.
·
Friday, 04 March 2016 11:01
·
0 Likes
·
0 Votes
·
0 Comments
·
ok, if you want to reuse this I'll share the updated code we now use:

in mailbox.php, DiscussMailerMessage->extractPart method changed:

/*
* Application or Image
*/
elseif ($type == 3 || $type == 5)
{
$myAttachment = array();
$myAttachment['mime'] = $subtype; // PDF or GIF etc.
$myAttachment['data'] = $data; // binary
$myAttachment['name'] = isset($params['name']) ? $params['name'] : $params['filename'];
$myAttachment['id'] = $id;
$myAttachment['size'] = $part->bytes;
$myAttachment['type'] = $type;
$this->attachment[] = $myAttachment;
}


and in mailqueue.php, DMMailQueue->processEmails method changed, checking for the MIME Type, which is now in the attachment['type'] property and if it's an image, do the image stuff...
So no need to have pdf, PDF in the list of $imgExts.

                                       // Check if MIME Type is "image" (TYPEIMAGE = 5)
if ($attachment['type'] == 5) {
// @task: check if the attachment has file extension. ( assuming is images )
$imgExts = array('jpg', 'png', 'gif', 'JPG', 'PNG', 'GIF', 'jpeg', 'JPEG');
$imageSegment = explode('.', $attachment['name']);

//the following is probably not necessary for most other users - we unfortunately use Notes/Domino...
//Skip graycol.gif, which is inserted by Lotus notes on replies.
if ($attachment['name'] == "graycol.gif") {
continue;
}

if (!in_array($imageSegment[count($imageSegment) - 1], $imgExts)) {
$attachment['name'] = $attachment['name'] . '.jpg';
}
}
·
Friday, 04 March 2016 21:38
·
0 Likes
·
0 Votes
·
0 Comments
·
Hey there,

I am really sorry for the delay of this reply as it is a weekend for us here.

Thanks for sharing the update code again

By the way, are you programmer?
·
Saturday, 05 March 2016 14:23
·
0 Likes
·
0 Votes
·
0 Comments
·
No, I am not a programmer (at least not professional), but I know how to google, I can read manuals like http://php.net/manual/en/function.imap-fetchstructure.php and I like to solve problems
·
Monday, 07 March 2016 19:11
·
0 Likes
·
0 Votes
·
0 Comments
·
Nice

As a gentle reminder, kindly start a new thread if you have any other issue in the future so it will be easier for us to manage your inquiry. I will lock and mark this thread as resolved.
·
Tuesday, 08 March 2016 09:57
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post