ElkArte Community

Elk Development => Bug Reports => Topic started by: Steeley on November 27, 2020, 01:27:53 am

Title: [SOLVED]Email Attachments attached to Wrong Post..
Post by: Steeley on November 27, 2020, 01:27:53 am
In reference to the following quote/post (version 1.1.3)


One more thing -- and I'm so sorry to keep bugging you about all this!

I've tried replying by email with a file attachment and the attachments gets posted to the forum but gets attached to the wrong reply (see screenshot, the PDF file 'billing units' is supposed to be attached to the last reply.) The attachment doesn't seem to make it through by email.

Any suggestions? Known bug?

..apparently persists in the ElkArte version currently running as I post this. JPalmer reports HERE (https://www.elkarte.net/community/index.php?topic=5886.msg41589#msg41589). 

@Spuds - did you find that as a bug (https://www.elkarte.net/community/index.php?topic=5196.msg36965#msg36965) back then, as you were going to investigate?

(I can't see emailed attachments posted anywhere in the thread here, or in my own forum, but that's a different problem..).

Update: once radu81 "approved" the attachment, I could see it in that thread, but in the post I replied to, not in the reply post the attachment was the payload of, which becomes, now, three issues:

1 - Like the email attachments appearing in edweis's forum v. 1.1.3 (in the wrong post), the problem of emailed attachments also appearing in the wrong post persists in this forum v. ? (once moderator approved).

2 - Emailed attachments do not show up in my forum v.1.1.6, at all, in spite of email attachments configured - Allow email file attachments to be posted is checked.
(I am using the cron job method, not the IMAP method - could that be the difference? I'm also using PHP 7.2. which I mention only because some behavior anomalies are now being observed and reported between 7.2 and 7.3 and 7.4)

3 - Last - (more a curiosity) why could JPalmer see the attachment in his post that I replied to, but not me, BEFORE it was approved by the moderator? (And then once moderator approved, I could see it...in the wrong post..)

I "really" need to get emailed attachments working, and working correctly, in my forum. Thoughts?

-Steeley
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 04, 2020, 04:54:21 am
Update: It turns out that attachments WILL go through in my forum (1.1.6) just like they do in 1.1.3 and ElkArtes 1.1.5, ..BUT...  the emailed attachment has to be in a reply to a reply..  Then the attachment posts in the message being replied to, not in the reply it was attached to.
If the emailed attachment email is starting a new topic, the attachment disappears completely (since there's no previous message to attach it to).

Another issue popped up during testing..  I'll post another bug report regarding starting a new topic via email by changing the subject.
Title: Re: Email Attachments attached to Wrong Post..
Post by: emanuele on December 06, 2020, 08:15:11 pm
Could you please reply to this topic? I want to try posting an attachment by email.
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 06, 2020, 08:30:17 pm
Here's an email reply, with an attachment payload, emanuele.

(It will probably end up in your post, not mine..)

-Steeley


Did you exchange, a walk-on part in the war for a lead role in a cage? [~ Pink Floyd: "Wish You Were Here"]

On 6 Dec 2020 at 19:15, emanuele via ElkArte Community wrote:

> Could you please reply to this topic? I want to try posting an attachment by > email.

Bugs creator.

Features destroyer.
 Template killer.
Title: Re: Email Attachments attached to Wrong Post..
Post by: emanuele on December 06, 2020, 08:35:48 pm
I'd need another, I forgot I turned notifications off. xD
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 06, 2020, 08:55:27 pm
OK, here's another...

And the attachments need to be moderator approved apparently (at least for me to see it)

-Steeley

Did you exchange, a walk-on part in the war for a lead role in a cage? [~ Pink Floyd: "Wish You Were Here"]

On 6 Dec 2020 at 19:35, emanuele via ElkArte Community wrote:

I'd need another, I forgot I turned notifications off. xD >

Bugs creator.

Features destroyer.
 Template killer.
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 06, 2020, 09:23:31 pm
I'd need another, I forgot I turned notifications off. xD

BTW, I don't believe attachments posted in the forum will be included in email notifications sent out by Elk..
(And that's not a complaint. In my opinion, it's preferable - if they want to see it, click the link in the email and log in...)
Title: Re: Email Attachments attached to Wrong Post..
Post by: emanuele on December 06, 2020, 09:56:13 pm
Testing out reply with attachments Steeley via ElkArte Community wrote on 12/6/20 9:23 PM:
Quote

Quote

On: Sun Dec 6, 2020 emanuele Wrote: I'd need another, I forgot I turned notifications off. xD

BTW, I don't believe attachments posted in the forum will be included in email notifications sent out by Elk..
// Deep inside every dilemma lies a solution that involves explosives //
Title: Re: Email Attachments attached to Wrong Post..
Post by: emanuele on December 06, 2020, 10:09:30 pm
Tracked:
https://github.com/elkarte/Elkarte/issues/3415
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 06, 2020, 11:36:29 pm
Tracked:
https://github.com/elkarte/Elkarte/issues/3415

OK, I've created a github account. Should I participate further there or standby here?

I'm considering trying your suggested fix and see what happens..
I'm just not sure at what point the message with attachment is assigned a message ID (if message ID for the attachment is set to "0") and whether a subsequent message ID assignment will "lose" the attachment.
I think that's what happens if the email is a NEW topic.. (no message ID), and thusly it appears the attachment is "lost" (It doesn't end up in the attachments folder, at all)
I misspoke, the attachment ends up in the attachments folder (If I'm going to test the function, I should enable it first as emanuele said). The attachment and its thumbnail are registered in the db (table: eln0_attachments) and linked to message ID "0".
As there is no message id 0 "it just sits there".. .

It appears that new topic email posts with attachments mimic the proposed fix (setting message id to "0"). and when the message posts with it's new message ID, the attachment (or the database) isn't updated with the new message id, and gets orphaned.

Title: Re: Email Attachments attached to Wrong Post..
Post by: Spuds on December 07, 2020, 12:48:04 am
I'm slowly getting around to looking at this some more ... well at all.   I do feel what you found is correct, the attachment is getting its id from the reply and adding it there instead of the "new"post. which should be 0 nods

I've been in the middle of changing from my vagrant environment to a docker one and am still working things out.  At least I now have php7.4 and Elk 1.1.7 set up so can begin to fix some of those annoyances.  Setting up various php/db/elk stacks is very easy as well.

Trying out a mailhog container to help debug the PBE issues but still have work to do to make it useful, if it can even do what I want!
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 08, 2020, 08:54:50 am
I've been in the middle of changing from my vagrant environment to a docker one and am still working things out.

I'm retired, my dockers are in a bottom drawer somewhere and I've transitioned back to full vagrant caparison. People even hand me spare change.. Life is grand..
Title: Re: Email Attachments attached to Wrong Post..
Post by: Spuds on December 08, 2020, 09:41:22 pm
Who can ever forget the era of fat arsed docker jeans :D
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 08, 2020, 10:43:44 pm
Who can ever forget the era of fat arsed docker jeans :D
Speaking of which.. would someone please tell me what the "PBE" acronym stands for? I'm old-skewelled.. it's not in my leather-bound C/pm user manuals anywhere (although I did discover the C/pm command "ERA" worked in DOS too - Gates, you sneaky bas..rd.)
Title: Re: Email Attachments attached to Wrong Post..
Post by: Spuds on December 08, 2020, 11:00:54 pm
Post By Email
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 09, 2020, 02:09:00 am
Post By Email

Ah.. my guess was "public beta environment " in ref to v 1.1.7...  Thanks!   :P
Title: Re: Email Attachments attached to Wrong Post..
Post by: Spuds on December 12, 2020, 03:28:01 pm
Back to the issue of this topic ...

There are two things here ... One is what was identified, that the post id should be set to zero such that they are processed but not yet owned by an existing message. 

Then on successful new message/reply creation, we need to also ```bindMessageAttachments``` to have the new message own the new attachments.  I have it fixed on my local.
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 12, 2020, 05:53:58 pm
Back to the issue of this topic ...

There are two things here ... One is what was identified, that the post id should be set to zero such that they are processed but not yet owned by an existing message. 

Then on successful new message/reply creation, we need to also ```bindMessageAttachments``` to have the new message own the new attachments.  I have it fixed on my local.

Yessir - didn't uncover the second until I looked at the code and database after the first was pinpointed by emanuale.
That is indeed outstanding news Spuds.  Email without an attachment is like Ray Charles at the Musée du Louvre.  ::)
If you can post the patch, or email it to me, I'll happily "beta test" it on my site..

Title: Re: Email Attachments attached to Wrong Post..
Post by: Spuds on December 12, 2020, 08:00:36 pm
Will do ... I'm actually making several changes as I saw some other opportunity --- or I'm off in the weeds :P

Either way I'll post the files to try when available, just save/rename your existing files in case you need to back out of the test!
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 12, 2020, 09:07:50 pm
Will do ... I'm actually making several changes as I saw some other opportunity --- or I'm off in the weeds :P

Either way I'll post the files to try when available, just save/rename your existing files in case you need to back out of the test!

Roger that...  just comment your changes so I know which ones to back out  :D  without dif'ing the files and guessing what is for what. .

., (and if you find my turtle let me know..)
Title: Re: Email Attachments attached to Wrong Post..
Post by: Spuds on December 12, 2020, 09:19:09 pm
Here are the changes .... for the attachment problem you need to save and replace (2) files
first in /sources/subs Emailpost.subs.php and then in /sources/controllers Emailpost.controller.php  Just to note this will not inline any attachments no matter how the email arrives, all attachments are done as below the post style. 

I also made some changes to the email parser that separate to the attachment issue.  This version should be a little lighter on the memory in some cases, it also does a better job at selecting the best representation of the email should it be a multipart style which most are.  See: EmailParse.class.php

And last up are some changes to the html2md class which is used during outbound emails.  This should improve the link length problem that was discussed in another thread, but while addressing that issue is when I noticed that some changes were needed to the above email parser.  So again in sources/subs Html2Md.class.php

Remember to save your old files, just do a rename to .sav and then place these new files in the right directories.
Title: Re: Email Attachments attached to Wrong Post..
Post by: Steeley on December 12, 2020, 11:27:59 pm
Here are the changes .... for the attachment problem you need to save and replace (2) files
first in /sources/subs Emailpost.subs.php and then in /sources/controllers Emailpost.controller.php  Just to note this will not inline any attachments no matter how the email arrives, all attachments are done as below the post style. 

I also made some changes to the email parser that separate to the attachment issue.  This version should be a little lighter on the memory in some cases, it also does a better job at selecting the best representation of the email should it be a multipart style which most are.  See: EmailParse.class.php

And last up are some changes to the html2md class which is used during outbound emails.  This should improve the link length problem that was discussed in another thread, but while addressing that issue is when I noticed that some changes were needed to the above email parser.  So again in sources/subs Html2Md.class.php

Remember to save your old files, just do a rename to .sav and then place these new files in the right directories.


Looks good so far, Spuds - I've tested new posts, replies, even handles "in-lines" (with a placeholder and attaching the file as normal which is good enough).

I'll flag @JPalmer as it looks like you worked over some of his code changes (https://www.elkarte.net/community/index.php?topic=5756.msg40638#msg40638) in the course of your efforts too. I think he was also fussing over the html line length (https://www.elkarte.net/community/index.php?topic=5883.msg41565#msg41565) issue.
He'll have to test that out for joy, mine is profuse..  thanks!