Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

3.8 KB
Raw Blame
use chrono::{DateTime, Utc};
use models_pagination::Identify;
use uuid::Uuid;

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Attachment {
    pub id: Uuid,
    #[allow(unused)]
    pub(crate) thread_id: Uuid,
    pub message_id: Uuid,
    // a different value is returned by the gmail API for this each time you fetch a message -
    // don't make the mistake of using it to uniquely identify an attachment
    pub provider_attachment_id: Option<String>,
    pub filename: Option<String>,
    pub mime_type: Option<String>,
    pub size_bytes: Option<i64>,
    pub content_id: Option<String>,
    pub created_at: DateTime<Utc>,
}

impl Identify for Attachment {
    type Id = Uuid;

    fn id(&self) -> Self::Id {
        self.id
    }
}

/// A provider attachment on a message.
#[derive(Debug, Clone)]
pub struct MessageAttachment {
    pub reference_url: Option<String>,
    /// Database ID of the attachment.
    pub db_id: uuid::Uuid,
    /// Provider attachment ID.
    pub provider_id: Option<String>,
    /// Original filename.
    pub filename: Option<String>,
    /// MIME type.
    pub mime_type: Option<String>,
    /// Size in bytes.
    pub size_bytes: Option<i64>,
    /// SFS (static file storage) ID.
    pub sfs_id: Option<uuid::Uuid>,
    /// Content ID (for inline attachments).
    pub content_id: Option<String>,
}

/// A draft attachment uploaded to S3.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct AttachmentDraft {
    /// Unique ID of the draft attachment record.
    pub id: uuid::Uuid,
    /// ID of the draft message this attachment belongs to.
    pub draft_id: uuid::Uuid,
    /// Original file name.
    pub file_name: String,
    /// MIME type.
    pub content_type: String,
    /// SHA-256 hash.
    pub sha: String,
    /// File size in bytes.
    pub size: i32,
    /// S3 object key.
    pub s3_key: String,
    /// Bytes have not yet been verified; sending must wait for completion.
    #[serde(default)]
    pub upload_pending: bool,
    /// Original Content-ID retained when transferring a provider attachment.
    #[serde(default)]
    pub content_id: Option<String>,
    /// Whether the attachment is referenced inline by the message body.
    #[serde(default)]
    pub is_inline: bool,
}

/// The most raw bytes one outgoing message may attach in total. Gmail caps
/// the encoded message at 25 MB; base64 adds about a third, so 18 MB of raw
/// content is the safe ceiling the draft attachment API enforces too.
pub const MAX_DRAFT_ATTACHMENTS_BYTES: usize = 18_000_000;

/// A file resolved from a Macro document, ready to be staged as a draft
/// attachment. Produced by a [`DraftAttachmentSource`].
///
/// [`DraftAttachmentSource`]: crate::domain::ports::DraftAttachmentSource
#[derive(Debug, Clone)]
pub struct SourcedAttachment {
    /// The file name the recipient sees, extension included.
    pub file_name: String,
    /// The MIME type the attachment part is sent with.
    pub content_type: String,
    /// The file's raw bytes.
    pub bytes: Vec<u8>,
    /// Sent as part of the message body instead of as a file. The only such
    /// part is an invitation's `text/calendar` body (RFC 6047), which Gmail
    /// and Outlook answer with Yes, Maybe and No.
    pub is_inline: bool,
}

/// A forwarded attachment linking a draft to an original message's attachment.
#[derive(Debug, Clone)]
pub struct AttachmentForwarded {
    /// UUID of the original attachment.
    pub attachment_id: uuid::Uuid,
    /// ID of the draft message.
    pub draft_id: uuid::Uuid,
    /// Provider attachment ID for fetching from the provider API.
    pub provider_attachment_id: Option<String>,
    /// Provider message ID of the original message.
    pub message_provider_id: String,
    /// Original filename.
    pub filename: Option<String>,
    /// MIME type.
    pub mime_type: Option<String>,
    /// Size in bytes.
    pub size_bytes: Option<i64>,
}