Commit Graph
136 Commits
Author SHA1 Message Date
Sabrina Demagny 6d6bbea0d9 ✨(imap) improve IMAP import code, load folders for GMAIL and ORANGE
- Load folders for GMAIL and ORANGE
- Fix read issue with Gmail IMAP import (all messages were marked as read)
- Fix IMAP encoding for Gmail import
- Refactor monolithic import_imap_messages_task into smaller, focused functions
- Add IMAPConnectionManager context manager for better resource management
- Extract helper functions with single responsibilities

This refactoring improves code maintainability, readability, and testability
while maintaining backward compatibility with existing API.
2025-07-28 11:18:28 +02:00
Sabrina Demagny 03cd72f0fb 🐛(labels) support identical label slugs across different mailboxes
- Replace single label lookup with multiple labels filter in ThreadViewSet
- Allow filtering threads by label_slug across multiple mailboxes when user has access
- Expect empty results instead of 403 errors for inaccessible labels
- Add comprehensive tests for identical labels in different mailboxes scenarios

This change enables users with access to multiple mailboxes to filter threads
by label slug across all accessible mailboxes, while maintaining proper
permission checks and supporting mailbox-specific filtering.
2025-07-24 12:47:27 +02:00
Mathis ROUGETandJean-Baptiste PENRATH e32862e4b3 ✨(ai) add thread summary 2025-07-24 11:45:07 +02:00
Mathis ROUGETandJean-Baptiste PENRATH e08acda852 ✨(ai) setup ai service 2025-07-24 11:45:07 +02:00
Sabrina Demagny 65af318fb5 ✨(backend) add get_abilities for Mailbox
- Add pre-calculation of user access roles in MailboxViewSet list/retrieve methods
- Implement get_abilities method on Mailbox model for permission checking
- Add AbilitiesModelSerializer to MailboxSerializer for consistent abilities field
- Optimize database queries by reducing N+1 access lookups
- Add comprehensive test coverage for abilities and optimized queries

This optimization significantly reduces database queries when listing
mailboxes by pre-calculating user roles instead of querying for each
mailbox individually.
2025-07-22 09:34:09 +02:00
Sylvain ZimmerandGitHub 9b4ba9ba09 ✨(dns) add admin page for DNS records (#283)
* ✨(dns) add admin page for DNS records. Fixes #177

* 👷(dockerflow) add a flag to disable Dockerflow

* 💚(ghactions) fix check-api-update that was missing Orval

* 💚(ci) fix tests that depended on Keycloak

* ♻️(admin) refactor CopyableInput into a separate component

* 🎨(dns) improve code style
2025-07-21 14:41:08 +02:00
Sylvain ZimmerandGitHub cc858e75e4 ✨(admin) improve Admin mailbox management page (#284)
This fixes a few small anoyances and adds a new field Mailbox.is_identity
to the models so that we can save what type of mailbox the admin created.
2025-07-21 10:47:06 +02:00
Sylvain ZimmerandSabrina Demagny 4545f4ff48 ✨(roles) implement MailboxAccessRole.SENDER 2025-07-18 14:11:29 +02:00
Sylvain Zimmer cfb417d80b 🐛(admin) add the ability to add mailbox accesses by email
This fixes the admin panel where users searched among the same
maildomain could correctly be added by their uuid, but when entering
an arbitrary email, the email and not the uuid gets sent in the POST
mailbox access. This might get replaced later when we have a proper
invitation system for external emails.
2025-07-18 00:00:00 +02:00
Sabrina Demagny 73d0f7476d 🐛(labels) implement cascading label rename with hierarchical tree fix
- Add cascading rename functionality to Label model save method
- Update all child labels when parent label is renamed
- Clean up orphaned parent labels that are no longer referenced
- Fix hierarchical tree construction in LabelViewSet list method
- Handle orphaned child labels by treating them as root labels
- Add comprehensive test for parent label rename scenarios

This ensures that when a parent label is renamed, all its children
are automatically updated to maintain the hierarchy, and the API
correctly displays all labels even when some parents are missing.
Fix #278
2025-07-17 17:17:49 +02:00
jbpenrath 0c79a169aa 🔊(front) setup posthog
Setup posthog and create a feedback button that is displayed
if a posthog survey id is provided through envvars
2025-07-16 22:22:25 +02:00
jbpenrath 7bd5a42e38 🏷️(openapi) types properly the ConfigViewset
Decorate ConfigViewset to be typed properly then regenerate
openapi schema and client.
2025-07-16 22:22:25 +02:00
jbpenrath 97c55bd7f0 🏷️(global) fix openapi schema and typescript types
Enhance the `IntegerChoicesField` to be well interpreted by drf
spectacular to generate a clean OpenAPI Schema then fix Typescript
issues once the api types have been fixed.
2025-07-16 15:04:26 +02:00
Sabrina Demagny ffa361f5f9 🐛(draft) handle MessageRecipient constraint error in draft API
Prevents 400 Bad Request error when there are simultaneous updating draft
Fixes the constraint error "Un objet Message recipient avec ces champs Message, Contact et Type existe déjà".
2025-07-16 01:34:55 +02:00
Sylvain Zimmer f29ba226e6 🐛(drafts) fix concurrent updates of drafts with blob delete 2025-07-15 23:13:07 +02:00
Sylvain ZimmerandGitHub f1a89a5bdb ✨(all) refactor several areas before 0.1 release (#265)
We are going to release a 0.1 version soon, along with our first production deployment. Starting from there, migrations and a consistent developer experience will be officially supported. To make that easier, this large patch cleans up several areas:
 * Reset migrations one last time
 * Update models for storage efficiency (move textchoices to integerchoices on high-volume tables)
 * Use Blobs for mail mime data and draft bodies. Having them in a separate PG table is a first step, we will later start offloading them to object storage.
 * Add default ZSTD compression to blobs
 * Add per-domain DKIM Keys
 * Add DNS check and provisioning, with a first Scaleway provider
 * Fix Keycloak user provisioning
 * Fix Attachment storage, they are now stored individually only at the drafting stage. Afterwards they are extracted from the main blob. This may be optimized later but at least we only store once. For JMAP compatibility, this requires using fake IDs in the blob API route.
 * Add a management command and recurring task to retry unsent messages
 * Improve the local developer experience with new ports and make commands
 * Repackage MTA-in and MTA-out to be closer to Backend: Poetry, multi-step Dockerfile, move compose and makefile to the root
 * Migrate to OpenSearch
 * Improve overall documentation and add a self-hosting page

Contributes to #177 and #185
2025-07-15 10:41:55 +02:00
Sabrina Demagny e1940295dc ✨(api) add dynamic abilities field to MailDomain API
- Add get_abilities() method to MailDomain model for permission-based abilities
- Update MailDomainAdminSerializer to inherit from AbilitiesModelSerializer
- Add RetrieveModelMixin to MailDomainAdminViewSet for detail endpoints
- Optimize queries with JOIN and annotation for regular users
- Add prefetch_related for superusers to avoid N+1 queries
- Add comprehensive tests for abilities functionality and query optimization
- Add new test file for MailDomain model abilities

The abilities field dynamically controls user permissions based on their role
in the mail domain, with optimized database queries to maintain performance.
2025-07-11 12:36:20 +02:00
jbpenrath 3c8bb9f6a3 👽️(api) update openapi schema and api client
Run `make api-update`
2025-07-10 18:05:00 +02:00
jbpenrathandSylvain Zimmer 0c44e7803a ✨(backend) complete admin maildomain api
- Create user (if needed) and mailbox access on mailbox creation
- If identify provider is keycloak, generate a one time password
at mailbox creation
- At nested endpoint to search users related to a maildomain

Co-authored-by: Sylvain Zimmer <sylvain@sylvainzimmer.com>
2025-07-10 18:05:00 +02:00
Sabrina Demagny b1daf05da6 ✨(api) add AbilitiesModelSerializer with exclude_abilities option
- Create AbilitiesModelSerializer base class that dynamically controls abilities field inclusion
- Refactor UserSerializer to inherit from AbilitiesModelSerializer
- Add exclude_abilities parameter to prevent abilities serialization in nested contexts
- Update MailboxAccessReadSerializer and MailboxAccessNestedUserSerializer to exclude abilities when nested
- Remove abilities from UserSerializer Meta fields as it's now handled dynamically
2025-07-10 17:18:55 +02:00
Sabrina Demagny f3b5cccf5d ✨(api) Allow superuser+staff to view all mail domains in admin API
- Add condition in MailDomainAdminViewSet.get_queryset() to return all domains
  when user is both superuser and staff
- Add comprehensive tests covering all user permission combinations:
  * superuser + staff: can see all domains
  * superuser only: cannot see all domains (empty list)
  * staff only: cannot see all domains (empty list)
  * staff with domain access: can only see accessible domains
- Maintain existing behavior for regular users and domain admins

This change ensures that superusers with staff privileges have full
administrative access to all mail domains through the admin API,
while maintaining proper access control for other user types.
2025-07-10 15:45:44 +02:00
Sabrina Demagny d3df815d1f ✨(backend) add user abilities system for mail domain permissions
- Add get_abilities() method to User model to determine user permissions
- Add abilities field to UserSerializer to expose permissions via API
- Implement permission logic for create_maildomains and view_maildomains
- Add comprehensive tests for User model abilities method
- Add integration tests for abilities field in users/me endpoint
- Support superuser+staff, mail domain access, and regular user scenarios

The abilities system provides granular permission control for mail domain
operations, allowing the frontend to adapt UI based on user capabilities.
2025-07-10 14:34:49 +02:00
Sabrina Demagny 260b27f6e0 ✨(api) add multi-word search on contact name and email
- Add ability to search contacts by multiple keywords (AND logic)
  on name and email, in contacts endpoint.
- Adapt and enrich tests to cover multi-word search,
  case sensitivity, and name/email combination.
2025-07-08 12:23:17 +02:00
Sabrina Demagny 604f7121a2 🐛(api) correct alphabetical sorting of labels with accented characters
- Change label sorting from name-based to slug-based ordering in list view
- Use slug ordering for initial queryset to ensure consistent sorting
- Maintain name-based sorting in create method for consistency
- Fixes issue where "État civil et cimetière" appeared at the end

The slug-based sorting provides more predictable alphabetical ordering
since slugs are normalized versions of names without accents.
2025-06-24 17:31:57 +02:00
Sabrina Demagny 1688ef70f7 💚(lint) run make lint 2025-06-23 11:44:23 +02:00
jbpenrath 6beac632b6 ✨(front) list labels in left panel and allow to edit them
Load and display labels in left panel. Add also a modal to
create/edit/delete labels.
2025-06-20 00:58:11 +02:00
Sabrina Demagny b2b71cc405 🐛(api) fix partial update of label 2025-06-20 00:15:35 +02:00
jbpenrath 95f78e4a02 ✨(front) upload mailbox archive as blob
To import old messages from an archive we must now upload the archive file
as a blob then provide the blobId to endpoint to import messages.
2025-06-20 00:13:50 +02:00
Sabrina DemagnyandJean-Baptiste PENRATH eee7afa65c ✨(backend) upload blob for eml and mbox import 2025-06-20 00:13:50 +02:00
Sabrina Demagny ce945259c8 💚(lint) run make lint
A `make lint` run was forgotten in the last commit
2025-06-19 13:45:09 +02:00
jbpenrath e263c56450 ♻️(frontend) update thread stats and thread panel after api refactoring
We recently refactor the way we process thread stats and the filters to list
threads. We have to update the front to work with this new behavior.
2025-06-19 02:05:41 +02:00
jbpenrath 0d4e4f3536 💄(front) clean a little bit label badges
We recently display label badges into thread-item. We revamp that
a little bit to improve code structure and prepare the layout
for further improvements.
2025-06-19 02:05:41 +02:00
Sylvain ZimmerandJean-Baptiste PENRATH 6fd271bed8 ♻️(flags) refactor Thread flags and stats
Migrate from counters to simple flags, because the frontend needs
counts of threads, not sums of counts of messages. Also prepare
for spam and archive features.
2025-06-19 02:05:41 +02:00
Sabrina Demagny e18732bb47 ♻️(labels) move parent labels creation logic
Put the logic into Label model's save() method to guarantee the invariant always holds,
even when using the admin interfacee uses, the shell, bulk operations, or any code path.
2025-06-18 11:21:03 +02:00
Sabrina Demagny a500eadde8 💚(api): ensure consistent thread ordering in list endpoint
- Add secondary ordering by created_at to prevent flaky test results
- When threads have the same messaged_at value, order by newest created_at first
- Ensures deterministic API responses for better test reliability
2025-06-17 19:47:53 +02:00
Sabrina Demagny ad179ee258 ✨(api) allow to list threads by label
Add the ability to filter threads by label slug in the thread list endpoint. This feature
enables users to view all threads associated with a specific label.

Changes:
- Add label_slug query parameter to ThreadViewSet list endpoint
- Implement label-based filtering with proper permission checks
- Add OpenAPI documentation for the new label_id parameter
- Add comprehensive test suite for label filtering

Technical details:
- Filter threads by label while ensuring user has access to the label's mailbox
- Support combining label filter with existing filters (mailbox, search, etc.)
- Add proper error handling for invalid or inaccessible labels
- Add test coverage for various filtering scenarios:
  - Single label filtering
  - Combined label and mailbox filtering
  - Invalid label handling
  - Permission checks
  - Combined filters (label + unread/starred status)
2025-06-16 15:54:41 +02:00
Sabrina Demagny 6d11b9fef5 🐛(backend) fix task response returned
Ensure consistent state reporting across import task updates
2025-06-16 14:35:27 +02:00
Sylvain ZimmerandGitHub 460068b5d3 ✨(identity) add MailDomain management with Keycloak identity provider (#136)
This allows user creation, passwords reset and listing users from
Keycloak, plus a new MailDomainAccess model for admins.

* ✨(admin) add maildomainacess model, api route and backend tests

* ♻️(drf) simplify API code

* ✨(keycloack) add deployable keycloak to PaaS

* ✨(keycloak) add integration via API, upgrade to 26.x

* 🗑️(settings) remove invitation setting

* 🐛(tests) fix failing tests after rebase

* 🚨(all) fix lint
2025-06-16 10:03:40 +02:00
Sabrina Demagny b51fa58553 🐛(backend) prevent duplicate threads during message import
Avoid duplicate threads when importing the same file multiple times.

Changes:
- Moved duplicate message check to the start of deliver_inbound_message
- Maintains proper threading relationships while preventing duplicate threads

This ensures that:
- No duplicate threads are created when importing the same file multiple times

Test coverage:
- Updated existing import tests to check thread counts
- Verified that duplicate imports don't create new threads
2025-06-15 21:54:00 +02:00
Sabrina Demagny 2ff790afb1 ✨(api) add endpoints to manage labels
This commit implements a complete label management system with the following features:

- Add CRUD operations for labels with hierarchical support (using slash-based naming)
- Implement label-thread associations (add/remove threads to/from labels)
- Add comprehensive permission checks (ADMIN/EDITOR roles required for management)
- Support hierarchical label structure with automatic parent creation
- Add color customization for labels
- Implement proper slug generation for label names
- Add extensive test coverage for all label operations

Technical details:
- New LabelViewSet with list, create, update, delete operations
- Custom actions for thread management (add-threads, remove-threads)
- Hierarchical label structure with parent-child relationships
- Automatic parent label creation when creating nested labels
- Proper permission handling based on mailbox access roles
- Comprehensive test suite covering all edge cases
- OpenAPI documentation for all endpoints
2025-06-15 18:18:31 +02:00
jbpenrath 328c1616eb 👽️(frontend) update api client
Run `make api-update`
2025-06-15 16:05:35 +02:00
Sabrina Demagny c297137bf4 ✨(backend) improve MBOX file import compatibility
Enhance support for MBOX files from various email export tools by handling
both extensionless files and text/plain MIME type. This improves compatibility
with different export formats while maintaining security through proper
validation.

Changes:
- Add support for files named "mbox" without extension
- Allow text/plain MIME type for MBOX files (common in webmail exports)
- Keep application/mbox as the primary MIME type for MBOX files
- Update validation to check both MIME types and file extensions
- Add test cases for extensionless files and text/plain MIME type
- Update error messages to be more descriptive about supported formats

The validation now handles:
- Files with .mbox extension (application/mbox or text/plain MIME type)
- Files named "mbox" without extension
- Maintains strict validation to ensure text/plain is only accepted for MBOX files

This change improves compatibility with various email export tools and webmail
services while maintaining security through proper file validation.
2025-06-15 15:13:38 +02:00
Sabrina Demagny 761784e91c ✨(backend) use a celery task for eml import
Unify the import implementations to use celery task (eml, mbox, imap)
Same returns for all import tasks.
Update openapi schema.
2025-06-11 23:53:48 +02:00
Sabrina Demagny 55c3f2a081 👽️(api) fix openapi schema for import message
Fix and re-generate schema
2025-06-11 23:32:51 +02:00
Sabrina Demagny c603350703 ✨(api) add labels info on Thread
Add details of labels info on thread list
2025-06-11 09:38:56 +02:00
Sabrina Demagny 55a7b1e49f ✨(api) add endpoints to import messages
Refactor code to import messages and add endpoints to import messages
(.eml, .mbox, imap)
2025-06-05 18:23:10 +02:00
Sabrina Demagny d39932c353 💚(backend) fix lint and collectstatic needed
Fix lint failures and run collectstatic
before running tests
2025-06-02 16:47:29 +02:00
jbpenrath db7631fd67 👽️(openapi) fix thread access serializer type and update schema and api
The `accesses` property into the Thread object was not propertly typed so we
update the serializer to fix the type by using dedicated sub serializers then we
run `make api-update` to update schema and api client.
2025-05-26 15:54:37 +02:00
jbpenrath e4c67558e3 👽️(api) complete openapi schema and regenerate
Improve the description of the blob api endpoint then regenerate
schema and client api through `make api-update`. Furthermore we
also update FetchApi interface to manage boundary multipart content type
2025-05-22 15:59:17 +02:00
Jean-Baptiste PENRATHandGitHub 7ddcc668f3 💚(ci) add job check-api-state (#111)
Add a job to ensure that api schema and client
are up-to-date.
2025-05-21 22:22:27 +02:00