db/herodb/src/models/mcc/README.md
2025-04-04 13:17:40 +02:00

3.5 KiB

MCC (Mail, Calendar, Contacts) Core Models

This directory contains the core data structures used in the herolib MCC module. These models serve as the foundation for the mail, calendar, and contacts functionality.

Overview

The core models implement the Serde traits (Serialize/Deserialize) and crate database traits (Storable, SledModel), which allows them to be stored and retrieved using the generic SledDB implementation. Each model provides:

  • A struct definition with appropriate fields
  • Serde serialization through derive macros
  • Methods for database integration through the SledModel trait
  • Utility methods for common operations

Core Models

Mail (mail.rs)

The Mail models provide email and IMAP functionality:

  • Email: Main struct for email messages with IMAP metadata
  • Attachment: Represents a file attachment with file information
  • Envelope: Represents an IMAP envelope structure with message headers

Message (message.rs)

The Message models provide chat functionality:

  • Message: Main struct for chat messages with thread and recipient information
  • MessageMeta: Contains metadata for message status, editing, and reactions
  • MessageStatus: Enum representing the status of a message (Sent, Delivered, Read, Failed)

Calendar (calendar.rs)

The Calendar model represents a container for calendar events:

  • Calendar: Main struct with fields for identification and description

Event (event.rs)

The Event model provides calendar event management:

  • Event: Main struct for calendar events with time and attendee information
  • EventMeta: Contains additional metadata for synchronization and display

Contacts (contacts.rs)

The Contacts model provides contact management:

  • Contact: Main struct for contact information with personal details and grouping

Group Support

All models now support linking to multiple groups (Circle IDs):

  • Each model has a groups: Vec<u32> field to store multiple group IDs
  • Utility methods for adding, removing, and filtering by groups
  • Groups are defined in the Circle module

Utility Methods

Each model provides utility methods for:

Filtering/Searching

  • filter_by_groups(groups: &[u32]) -> bool: Filter by groups
  • search_by_subject/content/name/email(query: &str) -> bool: Search by various fields

Format Conversion

  • to_message(): Convert Email to Message

Relationship Management

  • get_events(): Get events associated with a calendar or contact
  • get_calendar(): Get the calendar an event belongs to
  • get_attendee_contacts(): Get contacts for event attendees
  • get_thread_messages(): Get all messages in the same thread

Usage

These models are used by the MCC module to manage emails, calendar events, and contacts. They are typically accessed through the database handlers that implement the generic SledDB interface.

Serialization

All models use Serde for serialization:

  • Each model implements Serialize and Deserialize traits through derive macros
  • Binary serialization is handled automatically by the database layer
  • JSON serialization is available for API responses and other use cases

Database Integration

The models are designed to work with the SledDB implementation through:

  • The Storable trait for serialization/deserialization
  • The SledModel trait for database operations:
    • get_id() method for unique identification
    • db_prefix() method to specify the collection prefix
  • Implementation of custom utility methods where needed