Commit Graph

63 Commits

Author SHA1 Message Date
Pascal Bleser
64433382ff groupware: improve email sanitization by using the mime package to parse the part type, in order to recognize HTML ones that need sanitization 2026-04-13 16:40:14 +02:00
Pascal Bleser
83e0f2ad1f groupware: add headers Unmatched-Path and Unsupported-Method to make
development of the web UI easier
2026-04-13 16:40:14 +02:00
Pascal Bleser
5d5abe6a29 groupware: add markAsSeen=true to mark an email as $seen before it is
retrieved
2026-04-13 16:40:14 +02:00
Pascal Bleser
dacb415ec6 groupware: add the Retry-After header in responses when the session cannot be retrieved 2026-04-13 16:40:14 +02:00
Pascal Bleser
ed93330144 groupware: add searching emails by their Message-Id + retrieving an email by its ID as message/rfc822 2026-04-13 16:40:14 +02:00
Pascal Bleser
42f3833340 groupware: add email HTML sanitization
* sanitize email text/html body parts using bluemonday

 * deps(groupware):
   - new dependency: github.com/microcosm-cc/bluemonday
   - transitive dependencies:
     - github.com/aymerick/douceur
     - github.com/gorilla/css
2026-04-13 16:40:14 +02:00
Pascal Bleser
c5b2c3dd94 groupware: add identity deletion 2026-04-13 16:40:14 +02:00
Pascal Bleser
ecebd99b37 groupware:
* made several email related operations multi-account:
   QueryEmailSnippets, QueryEmails, QueryEmailsWithSnippets

 * add GetIdentitiesForAllAccounts

 * add GetEmailsForAllAccounts

 * jmap: add CreateIdentity, UpdateIdentity; groupware: add
   GetIdentityById, AddIdentity, ModifyIdentity

 * add temporary workaround until Calendars, Tasks, Contacts are
   implemented in Stalwart when determining the default account for
   those: use the mail one in the mean time
2026-04-13 16:40:14 +02:00
Pascal Bleser
7af0f3e877 groupware: fix NPE when one of the accounts is a group account 2026-04-13 16:40:14 +02:00
Pascal Bleser
c0377479b7 groupware: accept both '_' and '*' as the 'default account' placeholder 2026-04-13 16:40:14 +02:00
Pascal Bleser
59f2d95d86 groupware: implement email updating and email keyword updating endpoints 2026-04-13 16:40:13 +02:00
Pascal Bleser
0645f0bd6e groupware: for /accounts/all/emails/latest/summary, rename the ?unread query parameter into ?seen as that is more intuitive 2026-04-13 16:40:13 +02:00
Pascal Bleser
2976bb7651 docs(groupware): fix basepath in OpenAPI, /groupware instead of /groupware/groupware 2026-04-13 16:40:13 +02:00
Pascal Bleser
5179942083 groupware: improve jmap integration tests
* use gofakeit instead of loremipsum, as it can also fake images for
   attachments

 * random emails for testing: generate threads, add attachments
2026-04-13 16:40:13 +02:00
Pascal Bleser
ca5167ddd8 groupware: add bootstrapping on / with quotas for all accounts 2026-04-13 16:40:13 +02:00
Pascal Bleser
768485f600 groupware: add /quota for all accounts 2026-04-13 16:40:13 +02:00
Pascal Bleser
1c754794f5 groupware: add quota API + add support for Accept-Language and Content-Language 2026-04-13 16:40:13 +02:00
Pascal Bleser
d44ded1408 groupware: add flag to currently ignore session capability checks for calendars, contacts and tasks, as those are not implemented in Stalwart yet; will need to remove it in the future 2026-04-13 16:40:13 +02:00
Pascal Bleser
a2b406d451 groupware: add JMAP capability checking (in part: for contacts, calendars, tasks) 2026-04-13 16:40:13 +02:00
Pascal Bleser
36c591376d groupware: add mock endpoints for tasklists and tasks 2026-04-13 16:40:13 +02:00
Pascal Bleser
cfdbcb89da groupware: implement JMAP Task specification 2026-04-13 16:40:13 +02:00
Pascal Bleser
6c37504c14 groupware: more mock data, added missing JMAP types 2026-04-13 16:40:13 +02:00
Pascal Bleser
2e3fa6ab97 groupware: add mock endpoints for addressbooks and contacts 2026-04-13 16:40:13 +02:00
Pascal Bleser
542d35e133 start websocket implementation, add endpoint for email summaries
* feat(groupware): start implementing JMAP websocket support for push
   notifications (unfinished)

 * groupware: add GetLatestEmailsSummaryForAllAccounts

 * add new vendored dependency: github.com/gorilla/websocket

 * jmap: add QueryEmailSummaries

 * openapi: start adding examples

 * openapi: add new tooling for api-examples.yaml injection

 * apidoc-process.ts: make it more typescript-y

 * bump @redocly/cli from 2.0.8 to latest 2.2.0
2026-04-13 16:40:13 +02:00
Pascal Bleser
9341c75d69 refactor(groupware): just use a function for the attachment picker
Minor: be more Go idiomatic: just use a function to pick the attachment
from an Email's attachment list instead of using an interface with
multiple iplementation structs.
2026-04-13 16:40:13 +02:00
Pascal Bleser
c2b69f79cf groupware: improved attachment APIs
* feat(groupware): add /accounts/{}/emails/{}/attachments

 * feat(groupware): add
   /accounts/{}/emails/{}/attachments?partId=&name=&blobId=
2026-04-13 16:40:13 +02:00
Pascal Bleser
5d02cab3e9 fix(groupware): fix JMAP error handling
* the JMAP error handling was not working properly, fixed it and added
   error definitions accordingly

 * add operations to retrieve mailbox roles and mailboxes by role for
   all accounts
2026-04-13 16:40:13 +02:00
Pascal Bleser
6db1809bf5 refactor(groupware): rename "Messages" to "Email" everywhere
There was really no reason to go with "Messages" as far as the
vocabulary of the Groupware API goes, since the objects those APIs serve
are "Emails", to stick with the wording of the JMAP specification.
2026-04-13 16:40:13 +02:00
Pascal Bleser
8622bba3db groupware: minor typo fixes 2026-04-13 16:40:13 +02:00
Pascal Bleser
2c8784bb83 feat(groupware): add fetching all mailboxes for all accounts
* add URL to retrieve all the mailboxes for all the accounts of a user,
   as a first use-case for an all-accounts operation, as
   /accounts/all/mailboxes

 * add URL to retrieve mailbox changes for all the mailboxes of all the
   accounts of a user, as a first use-case for an all-accounts
   operation, as /accounts/all/mailboxes/changes

 * change the defaultAccountId from '*' to '_', as '*' rather indicates
   "all" than "default", and we might want to use that for "all
   accounts" operations in the future

 * refactor(groupware): remove the accountId parameter from the logger()
   function, as it is not used anyways, but also confusing for
   operations that support multiple account ids
2026-04-13 16:40:12 +02:00
Pascal Bleser
fe1606e712 docs(groupware): OpenAPI improvements
* refactor some pkg/jmap and groupware methods to make more sense from
   an API point-of-view

 * add path parameter documentation, but automate it by injecting their
   definition into the OpenAPI YAML tree that is extracted from the
   source code using go-swagger as it is too cumbersome, repetitive and
   error-prine to document them in the source code; wrote a TypeScript
   file apidoc-process.ts to do so

 * add generating an offline HTML file for the OpenAPI documentation
   using redocly, and injecting a favicon into the resulting HTML; wrote
   a TypeScript file apidoc-postprocess-html.ts to do so
2026-04-13 16:40:12 +02:00
Pascal Bleser
0a406aeec1 refactor(groupware): session cache and DNS autodiscovery
* move the logging of the username and session state away from pkg/jmap
   and into services/groupware

 * introduce more decoupling for the session cache, as well as moving
   the implementation into groupware_session.go
2026-04-13 16:39:51 +02:00
Pascal Bleser
3a37108637 groupware: add DNS auto-discovery (currently disabled, needs testing) 2026-04-13 16:39:51 +02:00
Pascal Bleser
cc870e69e6 groupware: session handling improvements
* remove the baseurl from the JMAP client configuration, and pass it to
   the session retrieval functions instead, as that is really the only
   place where it is relevant, and we gain flexibility to discover that
   session URL differently in the future without having to touch the
   JMAP client

 * move the default account identifier handling from the JMAP package to
   the Groupware one, as it really has nothing to do with JMAP itself,
   and is an opinionated feature of the Groupware REST API instead

 * add an event listener interface for JMAP events to be more flexible
   and universal, typically for metrics that are defined on the API
   level that uses the JMAP client

 * add errors for when default accounts cannot be determined

 * split groupware_framework.go into groupware_framework.go,
   groupware_request.go and groupware_response.go

 * move the accountId logging into the Groupware level instead of JMAP
   since it can also be relevant to other operations that might be
   worthy of logging before the JMAP client is even invoked
2026-04-13 16:39:51 +02:00
Pascal Bleser
a38d8b7ffa groupware: fix debug server, was missing a lot of configuration options and was binding to :80 2026-04-13 16:39:51 +02:00
Pascal Bleser
aaf94d32be refactor(groupware): logging and metrics improvements
* some minor code refactorings to improve logging and metrics

 * more code documentation
2026-04-13 16:39:51 +02:00
Pascal Bleser
baebc91b8d groupware: improve metrics
* implement more metrics, in a more streamlined fashion

 * use concurrent-map to store SSE streams instead of a regular map with
   one big lock that will not scale when it grows, causing too much
   contention on that one lock

 * while testing error metrics, noticed a few bugs with error handling
   when Stalwart is down: fixed
2026-04-13 16:39:51 +02:00
Pascal Bleser
934178ae6a groupware: implement metrics
* implement a framework for metrics, with a few exemplary ones
2026-04-13 16:39:51 +02:00
Pascal Bleser
f85a527591 groupware: Etag handling
* implement correct Etag and If-None-Match handling, responding with
   304 Not Modified if they match

 * introduce SessionState and State string type aliases to ensure we are
   using the correct fields for those, respectively

 * extract the SessionState from the JMAP response bodies in the
   groupware framework instead of having to do that in every single
   groupware API

 * use uint instead of int in some places to clarify that the values are
   >= 0

 * trace-log how long a Session was held in cache before being evicted

 * add Trace-Id header handling: add to response when specified in
   request, and implement a custom request logger to include it as a
   field

 * implement a more compact trace-logging of all the methods and URIs
   that are served, to put them into a single log entry instead of
   creating one log entry for every URI
2026-04-13 16:39:51 +02:00
Pascal Bleser
b06596ebd4 groupware: initial related emails implementation with SSE 2026-04-13 16:39:51 +02:00
Pascal Bleser
c8660a635e groupware: add /bootstrap
* add a GET /accounts/{a}/boostrap URI that delivers the same as GET /
   but also mailboxes for a given account, in case the UI remembers the
   last used account identifier, to avoid an additional roundtrip

 * streamline the use of simpleError()

 * add logging of errors at the calling site

 * add logging of evictions of Sessions from the cache

 * change default Session cache TTL to 5min instead of 30sec
2026-04-13 16:39:51 +02:00
Pascal Bleser
4abf0b4364 groupware: swagger API documentation improvements
* add more documentation for properties

 * fixes after a bit of trial-and-error with go-swagger

 * fix email filter marshalling when there are no search criteria

 * introduce an apidoc.yml that contains Swagger data and is merged when
   generating the swagger.yml from sources
2026-04-13 16:39:51 +02:00
Pascal Bleser
5f3d4ce610 Groupware improvements
* ensure that all the jmap responses contain the SessionState

 * implement missing errors that were marked as TODO

 * moved common functions from pkg/jmap and pkg/services/groupware to
   pkg/log and pkg/structs to commonalize them across both source trees

 * implement error handling for SetError occurences

 * Email: replace anonymous map[string]bool for mailbox rights with a
   MailboxRights struct, as the keys are well-defined, which allows for
   properly documenting them

 * introduce ObjectType as an "enum"

 * fix JSON marshalling and unmarshalling of EmailBodyStructure

 * move the swagger documentation structs from groupware_api.go to
   groupware_docs.go

 * fix: change verb for /groupware/accounts/*/vacation from POST to PUT
2026-04-13 16:39:51 +02:00
Pascal Bleser
cdfd76c148 groupware: minor email searching response improvements + started implementing vacation response setting API 2026-04-13 16:39:51 +02:00
Pascal Bleser
a3bc0c0066 groupware: add identities of all accounts to the index resource 2026-04-13 16:39:51 +02:00
Pascal Bleser
8b6fbb6a3b groupware: fix email search, add variant that includes the full emails 2026-04-13 16:39:51 +02:00
Pascal Bleser
f2106ec809 groupware: fix email search, add variant that includes the full emails 2026-04-13 16:39:51 +02:00
Pascal Bleser
dd3c6a1f7f Groupware: refactor jmap package, implement Email/set, EmailSubmission
* refactor the jmap package to split it into several files as the
   jmap.api.go file was becoming too unwieldy

 * refactor the Groupware handler function response to be a Response
   object, to be more future-proof and avoid adding more and more
   return parameters while handling "no content" response as well

 * more godoc for the JMAP model

 * add Email creation, updating, deleting (Email/set,
   EmailSubmission/set)

 * add endpoints
   - POST /accounts/{accountid}/messages
   - PATCH|PUT /accounts/{accountid}/messages/{messageid}
   - DELETE /accounts/{accountid}/messages/{messageid}
2026-04-13 16:39:51 +02:00
Pascal Bleser
36537b88e4 groupware: implement message search with snippets 2026-04-13 16:39:51 +02:00
Pascal Bleser
e3e58e28c1 groupware: blob streaming (upload and download) 2026-04-13 16:39:51 +02:00