database

package
v0.0.0-...-f6fa6ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package database provides contact resolution functionality.

Package database provides functionality for reading iMessage data from chat.db.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppleTimeToTime

func AppleTimeToTime(appleTime int64) *time.Time

AppleTimeToTime converts Apple's timestamp format to Go time.Time. Apple uses nanoseconds since 2001-01-01, while Unix uses seconds since 1970-01-01. The difference is 978307200 seconds.

func CloseDB

func CloseDB()

CloseDB closes the shared database connection pool. Call this during application shutdown for a clean exit.

func DB

func DB() (*sql.DB, error)

DB returns the shared database connection pool. The pool is lazily initialized on first call and reused for all subsequent queries.

func ExtractTextFromAttributedBody

func ExtractTextFromAttributedBody(data []byte) string

ExtractTextFromAttributedBody extracts plain text from an attributedBody blob. The attributedBody column contains a serialized NSAttributedString.

func GetAttachmentsForMessages

func GetAttachmentsForMessages(messageIDs []int64) (map[int64][]Attachment, error)

GetAttachmentsForMessages retrieves attachments for multiple message IDs in a single query and returns them keyed by message ID.

func GetConnection

func GetConnection() (*sql.DB, error)

GetConnection creates a new standalone connection to the iMessage database. Deprecated: Use DB() for the shared connection pool instead.

func GetContactName

func GetContactName(identifier string) string

GetContactName returns the contact name for a phone number or email.

func GetDBPath

func GetDBPath() string

GetDBPath returns the path to the iMessage database.

func GetPhoneVariants

func GetPhoneVariants(phone string) []string

GetPhoneVariants generates common variants of a phone number for matching.

func GetUnreadCount

func GetUnreadCount() (int, error)

GetUnreadCount returns the count of unread messages.

func NormalizePhoneNumber

func NormalizePhoneNumber(phone string) string

NormalizePhoneNumber normalizes a phone number to just digits for comparison.

func PreloadContacts

func PreloadContacts()

PreloadContacts loads contacts into memory.

func ResolveSender

func ResolveSender(isFromMe bool, senderID string) string

ResolveSender resolves a sender identifier to a display name.

Types

type Attachment

type Attachment struct {
	AttachmentID int64
	Filename     string // original filename
	FilePath     string // full path on disk (~ expanded)
	MIMEType     string
	UTI          string // e.g. public.jpeg, public.heic
	TotalBytes   int64
	IsImage      bool
}

Attachment represents a file attachment on an iMessage.

func GetAttachmentsForMessage

func GetAttachmentsForMessage(messageID int64) ([]Attachment, error)

GetAttachmentsForMessage retrieves attachments for a single message ID.

type ContactResolver

type ContactResolver struct {
	// contains filtered or unexported fields
}

ContactResolver resolves phone numbers and email addresses to contact names.

func NewContactResolver

func NewContactResolver() *ContactResolver

NewContactResolver creates a new ContactResolver.

func (*ContactResolver) GetContactCount

func (cr *ContactResolver) GetContactCount() int

GetContactCount returns the number of loaded contacts.

func (*ContactResolver) Resolve

func (cr *ContactResolver) Resolve(identifier string) string

Resolve resolves an identifier (phone/email) to a contact name.

type Conversation

type Conversation struct {
	ChatID          int64
	ChatIdentifier  string
	DisplayName     string
	Service         string
	LastMessageDate *time.Time
	LastMessageText string
	UnreadCount     int
	Participants    []string
}

Conversation represents a chat/conversation.

func GetContactByIdentifier

func GetContactByIdentifier(identifier string) (*Conversation, error)

GetContactByIdentifier looks up a contact by phone number or email.

func GetConversations

func GetConversations(limit int) ([]Conversation, error)

GetConversations retrieves a list of recent conversations.

type Message

type Message struct {
	MessageID   int64
	Text        string
	Date        *time.Time
	IsFromMe    bool
	IsRead      bool
	Service     string
	Sender      string
	ChatID      int64
	ChatIdent   string
	ChatName    string
	Attachments []Attachment
}

Message represents an iMessage.

func GetMessages

func GetMessages(chatID int64, chatIdentifier string, limit int) ([]Message, error)

GetMessages retrieves messages from a specific conversation.

func SearchMessages

func SearchMessages(query string, limit int) ([]Message, error)

SearchMessages searches for messages containing the given text.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL