Skip to main content
Topic: [SOLVED] Help on Post/reply by email (Read 223 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[SOLVED] Help on Post/reply by email

Sorry for bringing this up once again ... I have followed closely the discussion here, and I followed the advice(s) set out there.

After some fiddling with setting up mail forwarding at my hosting provider and the path to php binary, I think that incoming emails are now piped to the emailtopic.php script. At least I can see them coming in at the ElkArte section for "Moderation -> Unapproved Emails".

And here is the problem ... I do not get any information out of this mails, e.g. no "Subject", no "From", no "Body Text". The system alerts "Email ID not in Database", which might be an aftereffect of not detecting a sender address. The user I'm sending from IS registered in the database.

On a lighter note, also sending a bounce message from the admin page does fail with "Session verification failed. Please try logging out and back in again, and then try again."

Please advice what I could do to narrow down the problem. Any help is highly appreciated!

EDIT: Mark as "solved" ...

 

[SOLVED] Help on Post/reply by email

Reply #1
After excessive debugging I found a few items that I want to put up for discussion.

In my opinion there are several problems in the logic for creating new topics from email.

1. Detecting and separating a mail message in headers and body
File / function:
Code: [Select]
EmailParse.class.php:327 / _split_headers()

Problem:
The function tries to detect beginning and end of the header section by using regular expressions. The problem is that this function is called recursively for parsing the sections of a multipart message. The sequence is:
  • for the whole message
  • for first section
  • for second section
  • ...

As a matter of fact, when called for a section, this will never include a header. Hence the existing code will always return without filling the body block, since this is done by the second regular expression that fills the reg exp result in the $match[] array.

Solution:
Just delete / comment the header start check:
Code: [Select]
// Do we even start with a header in this boundary section?
// if (!preg_match('~^[\w-]+:[ ].*?\r?\n~i', $this->raw_message))
// {
// return;
// }

2. Separating of the sections of a mail message
File / function:
Code: [Select]
EmailParse.class.php:751 / _boundary_split()

Problem:
The function tries to detect beginning and end of the header section by locating the delimiting '--<boundary>' pattern. The problem is that defined by the mail RFC1342 the multipart section is finally ended by adding two more hyphens at the end of the line, i.e. "--<boundary>--".
In the existing approach this last line causes creation of a section that has no content other than '--'.

Solution:
Modify to suppress the creation of a section not only for empty section, but also for closing section:
Code: [Select]
// Nothing or end of multipart split?
// if (empty($part))
if (empty($part) or (strcmp($part, '--') == 0))
{
continue;
}

3. Reformating the body part of a message
File / function:
Code: [Select]
EmailFormat.class.php:365 / _clean_up()

Problem:
The charset parameter is not processed correctly. Towards the end of the function a couple of special characters are replaced in a dedicated way. This must not be done if the text is UTF-8 encoded. Unfortunately this is checked only for the capital letter variant 'UTF-8'. In my case the character set came in as 'utf-8' which consequently destroyed the content of the body text.
Solution:
Modify the check to be case insensitive:
Code: [Select]
// And its 1252 variants
if (strcasecmp($charset, 'UTF-8') !== 0)

The last item was particularly tricky as I only stumbled accidentally over the use of some German "Umlaut" character which caused some mails to fail.

I have made this changes locally to my server. What is the correct way of bringing the suggested changes into future versions of ElkArte? On a lighter note, I feel a little perplexed that this has not been brought up so far. I wonder how the "add topic by email" feature could ever work correctly. Any opinion on this?

Re: [SOLVED] Help on Post/reply by email

Reply #2
I have made this changes locally to my server. What is the correct way of bringing the suggested changes into future versions of ElkArte?
you can report on forum or also on github it's your choice

On a lighter note, I feel a little perplexed that this has not been brought up so far. I wonder how the "add topic by email" feature could ever work correctly. Any opinion on this?
I don't have the knowledge to comment an discuss about coding, I'm not a coder but a simple forum admin.
Consider that most of forum admins are not using this feature and I guess this is the reason why it has not been reported until now, I manage more than one elkarte forum and I never used or tested this feature.
I'm pretty sure that @emanuele or @Spuds will asnswer soon
 
Thanks for your report
sorry for my bad english

Re: [SOLVED] Help on Post/reply by email

Reply #3
I have made this changes locally to my server. What is the correct way of bringing the suggested changes into future versions of ElkArte?
you can report on forum or also on github it's your choice

Thanks for your help! I have opened the respective issues on github,