mail icon indicating copy to clipboard operation
mail copied to clipboard

feat(ocs): notify of new messages and provide API endpoint to retrieve its contents

Open miaulalala opened this issue 1 year ago • 3 comments

miaulalala avatar Jun 17 '24 16:06 miaulalala

Wrong PR

miaulalala avatar Jun 19 '24 15:06 miaulalala

@ChristophWurst shall I also expose an endpoint to download the attachments? Or is there a way to add them to the JSON without doing the base64_enocde dance? We have a download in the MessageController already that I could copy.

miaulalala avatar Jun 26 '24 20:06 miaulalala

@ChristophWurst shall I also expose an endpoint to download the attachments? Or is there a way to add them to the JSON without doing the base64_enocde dance? We have a download in the MessageController already that I could copy.

@miaulalala i wouldn't include attachments in the get method output... That can cause a lot of traffic for something that might not be used... on that note the attachments are already in the raw message, so I don't know if the raw message should be included unless requested that way...

This was the encoded attachment in the message I pulled.

inline; name=event.ics; filename=event.ics\r\n\r\nQkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOi0vL1NhYnJlLy9TYWJyZSBWT2Jq\r\nZWN0IDQuNS40Ly9FTg0KQ0FMU0NBTEU6R1JFR09SSUFODQpNRVRIT0Q6Q0FOQ0VMDQpCRUdJTjpW\r\nRVZFTlQNClVJRDpkZWM2NzQzNS1iN2QwLTQ0YTMtODQxMS0zOTFjYTZmNGJiY2ENCkRUU1RBTVA6\r\nMjAyNDA2MjVUMjE1ODA2Wg0KU0VRVUVOQ0U6Mw0KU1VNTUFSWTpUZXN0aW5nIFNpbmdsZXRvbiBB\r\nbGwgRGF5IEV2ZW50DQpEVFNUQVJUO1ZBTFVFPURBVEU6MjAyNDA3MDMNCkRURU5EO1ZBTFVFPURB\r\nVEU6MjAyNDA3MDQNCk9SR0FOSVpFUjtDTj1Vc2VyIE9uZTptYWlsdG86dXNlcjFAa3NhbWFpbC5j\r\nYQ0KQVRURU5ERUU7Q049VXNlciBUd286bWFpbHRvOnVzZXIyQGtzYW1haWwuY2ENCkVORDpWRVZF\r\nTlQNCkVORDpWQ0FMRU5EQVINCg==\r\n--SM8uFlts--\r\n\r\n"

SebastianKrupinski avatar Jun 26 '24 22:06 SebastianKrupinski

JSON response:

{
    "ocs": {
        "meta": {
            "status": "ok",
            "statuscode": 200,
            "message": "OK"
        },
        "data": {
            "uid": 5396,
            "messageId": "<kjsdflkdsjflksdkjf@geopod-ismtpd-39>",
            "from": [
                {
                    "label": "FromLabel",
                    "email": "[email protected]"
                }
            ],
            "to": [
                {
                    "label": "[email protected]",
                    "email": "[email protected]"
                }
            ],
            "replyTo": [
                {
                    "label": "ReplyToLabel",
                    "email": "[email protected]"
                }
            ],
            "cc": [],
            "bcc": [],
            "subject": "Subject",
            "dateInt": 1719374564,
            "flags": {
                "seen": true,
                "flagged": false,
                "answered": false,
                "deleted": false,
                "draft": false,
                "forwarded": false,
                "hasAttachments": false,
                "mdnsent": false,
                "important": true
            },
            "hasHtmlBody": true,
            "dispositionNotificationTo": "",
            "hasDkimSignature": true,
            "unsubscribeUrl": "sjfifjsdlksdjflksdjf",
            "isOneClickUnsubscribe": true,
            "unsubscribeMailto": null,
            "scheduling": [],
            "body": "Body data here",
            "attachments": [],
            "id": 186737,
            "isSenderTrusted": false,
            "smime": {
                "isSigned": false,
                "signatureIsValid": null,
                "isEncrypted": false
            }
        }
    }
}

miaulalala avatar Jul 01 '24 10:07 miaulalala

When an S/MIME encrypted message is fetched via MessageApiController::get() and the decryption fails (due to a missing key), a 404 response is returned with an empty message.

This could be improved by catching, retrying without fetching the body and adding a field bodyRawUrl field to the data response pointing to getRaw(). The HTTP status code should be 206 Partial Content.

We cannot get the body but the meta information of a message (to, cc, subject etc.) could still be interesting to an API consumer.

https://github.com/nextcloud/mail/blob/d7989048871d8d06e207178914cc216b0d6d5b69/lib/Controller/MessageApiController.php#L81-L92

Fetching with $loadBody = false in line 87 will return the IMAP message without the body but will not fail on missing keys.


The thrown exception in SmimeService::decryptDataFetch() has to adjusted accordingly. Currently, a ServiceException is thrown which cannot be distinguished easily from the the decryption error.

https://github.com/nextcloud/mail/blob/fefd2a77b8f7d098fe565b17d8ee58e345f4cb4d/lib/Service/SmimeService.php#L524-L526

st3iny avatar Jul 01 '24 17:07 st3iny