Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Entities

The SDK’s local data models are ObjectBox entities (pro.aduki.store.entities). Besides the four below the module holds Appointment, Service and Slot for scheduling.


1. Message Entity

package pro.aduki.store.entities

@Entity
data class Message(
    @Id var id: Long = 0,
    @Index var hex: String = "",
    @Index var mailbox: String = "",
    @Index var uid: Long = 0,
    @Index var threadId: String = "",
    var subject: String = "",
    var fromName: String = "",
    var fromEmail: String = "",
    var to: String = "",            // comma-separated addresses
    var preview: String = "",       // was `snippet` before 0.2.0
    var blob: String = "",
    var size: Long = 0,
    @Index var flags: Int = 0,      // SEEN=1, ANSWERED=2, FLAGGED=4, DELETED=8, DRAFT=16
    var keywords: String = "",      // other server flags, space-separated ("$Junk $Forwarded")
    var hasAttachment: Boolean = false,
    @Index var receivedAt: Long = 0, // was `date` before 0.2.0; epoch millis UTC
    var sentAt: Long = 0,
    var modseq: Long = 0,
    var created: Long = 0,
    var dirty: Boolean = false
) {
    fun seen(): Boolean
    fun flagged(): Boolean
    fun deleted(): Boolean           // `\Deleted`: hidden from lists and unread counts
    fun toggle(flag: Int)
    fun recipients(): List<String>
    fun sender(): String             // fromName, else fromEmail

    companion object {
        fun bits(flags: List<String>): Int        // server flags -> bitmask
        fun keywords(flags: List<String>): String // the non-system flags
        fun flagName(bit: Int): String?           // SEEN -> "\Seen"
    }
}

Field Definitions

FieldMeaning
hexServer id; a msg_<millis> placeholder until an outbox send completes.
mailbox, uidMailbox hex and the message’s UID in it (changes on a move).
threadIdConversation id (the message’s own id when it has no thread).
fromName, fromEmail, toParsed sender and recipients.
previewStart of the body text, from the server.
flagsBitmask of \\Seen, \\Answered, \\Flagged, \\Deleted, \\Draft.
keywordsEvery other server flag or keyword, space-separated.
hasAttachmentThe message has attachments.
receivedAt, sentAtArrival time and Date: header, epoch millis (UTC).
modseqThe server MODSEQ of the last change applied.
dirtyA local change is waiting in the outbox; sync keeps local flags and mailbox.

2. Mailbox Entity

Tracks mailbox folder metadata and RFC 7162 CONDSTORE sequence state.

package pro.aduki.store.entities

import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import io.objectbox.annotation.Index

@Entity
data class Mailbox(
    @Id var id: Long = 0,
    @Index var hex: String = "",
    var name: String = "",
    var role: String = "", // inbox, sent, trash, archive, drafts
    var uidnext: Long = 0,
    var uidvalidity: Long = 0,
    var modseq: Long = 0,
    var exists: Int = 0,
    var unseen: Int = 0
)

Field Definitions

FieldTypeAnnotationDescription
idLong@IdLocal ObjectBox primary key.
hexString@IndexUnique mailbox folder identifier hex.
nameString—User-facing folder display title (e.g. "Inbox", "Work").
roleString—Special-use role attribute: "inbox", "sent", "trash", "archive", "drafts".
uidnextLong—Predicted next IMAP UID assigned to incoming mail.
uidvalidityLong—Server mailbox generation token. Mismatches trigger full local re-seed.
modseqLong—Highest 64-bit CONDSTORE sequence counter committed locally.
existsInt—Total message count in the folder.
unseenInt—Unread message count badge.

3. Contact Entity

Stores address book contacts.

package pro.aduki.store.entities

import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import io.objectbox.annotation.Index

@Entity
data class Contact(
    @Id var id: Long = 0,
    @Index var hex: String = "",
    @Index var name: String = "",
    @Index var email: String = "",
    var phone: String = "",
    var company: String = "",
    var vcard: String = "",
    var ctag: String = "",
    var updated: Long = 0
)

4. Outbox Entity

Persists pending offline write-ahead actions for reliable background transmission.

package pro.aduki.store.entities

import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import io.objectbox.annotation.Index

@Entity
data class Outbox(
    @Id var id: Long = 0,
    @Index var hex: String = "",    // the message the action is about
    @Index var action: String = "", // "send", "flag", "move", "delete"
    var payload: ByteArray = byteArrayOf(),
    @Index var created: Long = System.currentTimeMillis(),
    var attempts: Int = 0,
    var nextRetry: Long = 0
)

5. Sync Entity

Persists synchronization cursor tokens and generation timestamps.

package pro.aduki.store.entities

import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import io.objectbox.annotation.Index

@Entity
data class Sync(
    @Id var id: Long = 0,
    @Index var target: String = "", // "contacts", "inbox", etc.
    var token: String = "",
    var timestamp: Long = 0
)