Z-Hub / Z-Push

Home of Z-Push
https://z-push.org
GNU Affero General Public License v3.0
94 stars 43 forks source link

Sending email with iphone and imap backend seems impossible #64

Closed JorisHansMeijer closed 5 months ago

JorisHansMeijer commented 5 months ago

Describe the issue When sending a email with the iphone I get a error. The logs show that the recipients can't be found. My guess is that the information for the email that needs to be send is completely missing. Sending emails is possible when I hack the code and add recipients by hand.

To Reproduce Steps to reproduce the behavior:

  1. Use imap backend
  2. Try to send email

// Z-PUSH LOGFILE 12/05/2024 07:44:13 [16095] [WARN] [joris] /volume1/web/Z-Push-2.7.3/src/include/mimeDecode.php:524 Uninitialized string offset: 0 (8) 12/05/2024 07:44:13 [16095] [WARN] [joris] /volume1/web/Z-Push-2.7.3/src/include/mimeDecode.php:891 mb_check_encoding(): Invalid encoding "" (2) 12/05/2024 07:44:13 [16095] [WARN] [joris] mimeDecode::_decodeBody(): invalid encoding in body: using 'UTF-8' instead of '' 12/05/2024 07:44:13 [16095] [WARN] [joris] /volume1/web/Z-Push-2.7.3/src/backend/imap/imap.php:2669 Undefined variable: recipients (8) 12/05/2024 07:44:13 [16095] [ERROR] [joris] Mail error: sendmail returned error code 127 12/05/2024 07:44:13 [16095] [ INFO] [joris] StatusException: BackendIMAP->sendMessage(): The email could not be sent - code: 120 - file: /volume1/web/Z-Push-2.7.3/src/backend/imap/imap.php:2673 12/05/2024 07:44:13 [16095] [WARN] [joris] HTTPReturnCodeException: BackendIMAP->sendMessage(): The email could not be sent - code: 500 - file: /volume1/web/Z-Push-2.7.3/src/lib/request/sendmail.php:152 12/05/2024 07:44:13 [16095] [FATAL] [joris] WBXML 10K debug data: 12/05/2024 07:44:13 [16095] [ INFO] [joris] User-agent: 'Apple-iPhone12C1/2105.236' 12/05/2024 07:44:13 [16095] [FATAL] [joris] Exception: (HTTPReturnCodeException) - BackendIMAP->sendMessage(): The email could not be sent 12/05/2024 07:44:13 [16095] [ INFO] [joris] cmd='SendMail' memory='1.82 MiB/4.00 MiB' time='0.35s' devType='iPhone' devId='s05locj5n56sdaqq525o8hp3uc' getUser='joris' from='192.168.1.79' idle='0s' version='2.7.3 ' method='POST' httpcode='500'

matidau commented 5 months ago

Hi @JorisHansMeijer,

From the warnings above it looks like there might have been a problem with the headers and the character encoding in the mime message. This may be affecting how it is parsing the recipients, I don't believe sendmail will accept an email without recipients.

A couple of questions: Was this a forwarded email or a new email entered on the iPhone? What Language do you have set on your phone? What Language was the email in if it is different from you phone's language?

And then a few more questions just to cover the config, in your imap config.php: What is IMAP_SMTP_METHOD set to? What is $imap_smtp_params set to?

Cheers, Mat

JorisHansMeijer commented 5 months ago

Hi,

Thanks for the quick response. Here some answers; It was a new email. I tried both reply and new but both have the same issue, The language I have set is dutch, I just typed some random characters (the repsly message was based on a dutch email),

I don't believe I get to the part where it has a correct message to send, but my settings are: define('IMAP_SMTP_METHOD', 'sendmail'); $imap_smtp_params = array( 'sendmail_path' => '/sbin/sendmail', 'sendmail_args' => '-i' // 'host' => 'ssl://smtp.strato.de', // 'port' => 465, // 'auth' => true, // 'verify_peer' => false, // 'verify_peer_name' => false, // 'allow_self_signed' => true, // 'username' => '-----------', // 'password' => '-----------' );

I tried both smtp and sendmail. Sendmail from the commandline is working ok).

JorisHansMeijer commented 5 months ago

Just as reference, here a somewhat more longer log:

12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->SendMail(): RFC822: 1 bytes forward-id: 'false' reply-id: 'false' parent-id: 'false' SaveInSent: 'true' ReplaceMIME: 'false' 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->SendMail(): We get the new message 12/05/2024 10:29:18 [21595] [WARN] [joris] /volume1/web/Z-Push-2.8.0_develop/src/include/mimeDecode.php:524 Uninitialized string offset: 0 (8) 12/05/2024 10:29:18 [21595] [WARN] [joris] /volume1/web/Z-Push-2.8.0_develop/src/include/mimeDecode.php:891 mb_check_encoding(): Invalid encoding "" (2) 12/05/2024 10:29:18 [21595] [WARN] [joris] mimeDecode::_decodeBody(): invalid encoding in body: using 'UTF-8' instead of '' 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->SendMail(): We get the From and To 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->getFromHeaderValue(): No From address defined, we try for a default one 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->setReturnPathValue(): No Return-Path address defined, we use From 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->SendMail(): is a new message or we are replacing mime 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->SendMail(): Copying new headers 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->SendMail(): Final mail to send: 12/05/2024 10:29:18 [21595] [WBXML] [joris] MIME-Version: 1.0 : From: xxxx@yyyyyyyyyyyy.org Return-path: xxxx@yyyyyyyyyyyy.org Content-Type: multipart/mixed; boundary="=_c09d6cf607ed4d4ffc470ff840aa2041"

12/05/2024 10:29:18 [21595] [WBXML] [joris] Body: This is a multi-part message in MIME format. Body: --=_c09d6cf607ed4d4ffc470ff840aa2041 Body: Content-Type: multipart/alternative; Body: boundary="=_37f09778a27ded4129db1e1206e98a8e" Body: Body: Body: --=_c09d6cf607ed4d4ffc470ff840aa2041-- Body:

12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->sendMessage(): SendingMail with sendmail 12/05/2024 10:29:18 [21595] [WARN] [joris] /volume1/web/Z-Push-2.8.0_develop/src/backend/imap/imap.php:2671 Undefined variable: recipients (8) 12/05/2024 10:29:18 [21595] [ERROR] [joris] Mail error: sendmail returned error code 127 12/05/2024 10:29:18 [21595] [DEBUG] [joris] BackendIMAP->sendMessage(): send return value 12/05/2024 10:29:18 [21595] [ INFO] [joris] StatusException: BackendIMAP->sendMessage(): The email could not be sent - code: 120 - file: /volume1/web/Z-Push-2.8.0_develop/src/backend/imap/imap.php:2675 12/05/2024 10:29:18 [21595] [WARN] [joris] HTTPReturnCodeException: BackendIMAP->sendMessage(): The email could not be sent - code: 500 - file: /volume1/web/Z-Push-2.8.0_develop/src/lib/request/sendmail.php:152 12/05/2024 10:29:18 [21595] [FATAL] [joris] WBXML 10K debug data: 12/05/2024 10:29:18 [21595] [ INFO] [joris] User-agent: 'Apple-iPhone12C1/2105.236' 12/05/2024 10:29:18 [21595] [FATAL] [joris] Exception: (HTTPReturnCodeException) - BackendIMAP->sendMessage(): The email could not be sent 12/05/2024 10:29:18 [21595] [DEBUG] [joris] LoopDetection->ProcessLoopDetectionTerminate() 12/05/2024 10:29:18 [21595] [ INFO] [joris] cmd='SendMail' memory='1.83 MiB/4.00 MiB' time='0.45s' devType='iPhone' devId='s05locj5n56sdaqq525o8hp3uc' getUser='joris' from='192.168.1.79' idle='0s' version='2.7.3 ' method='POST' httpcode='500' 12/05/2024 10:29:18 [21595] [DEBUG] [joris] -------- End

matidau commented 5 months ago

$imap_smtp_params = array( 'sendmail_path' => '/sbin/sendmail'

Do you mind running which sendmail and checking the path?

JorisHansMeijer commented 5 months ago

Screenshot from 2024-05-13 06-14-16

JorisHansMeijer commented 5 months ago

I got it fixed. It was fixed by using the .htaccess file like:


<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule .* - [E=HTTP_MS_ASPROTOCOLVERSION:%{HTTP:Ms-Asprotocolversion}]
        RewriteRule .* - [E=HTTP_X_MS_POLICYKEY:%{HTTP:X-Ms-Policykey}]
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule mod_expires.c>
        ExpiresActive Off
</IfModule>

<IfModule mod_alias.c>
        Redirect 308 /.well-known/caldav /baikal/dav.php
        Redirect 308 /.well-known/carddav /baikal/dav.php
        RewriteRule Microsoft-Server-ActiveSync /Z-Push-2.7.3/src/index.php [PT,L,QSA]
</IfModule>
matidau commented 5 months ago

Glad you got it to work 😊