internal

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UseWALMode bool

UseWALMode controls whether WAL journal mode is enabled for databases

Functions

func AuthMiddleware

func AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AuthMiddleware checks for a valid session cookie

func CleanExpiredSessions

func CleanExpiredSessions() error

CleanExpiredSessions removes all expired sessions

func ClearUploadProgress

func ClearUploadProgress()

ClearUploadProgress clears the upload progress

func CustomCORSMiddleware

func CustomCORSMiddleware() echo.MiddlewareFunc

CustomCORSMiddleware creates a custom CORS middleware that properly handles credentials

func DeleteSession

func DeleteSession(sessionID string) error

DeleteSession deletes a session by ID

func GenerateSessionID

func GenerateSessionID() (string, error)

GenerateSessionID generates a random session ID

func GetDateRange

func GetDateRange(userDB *sql.DB) (time.Time, time.Time, error)

func GetMessageMedia

func GetMessageMedia(userDB *sql.DB, messageID string) ([]byte, string, error)

func GetUserDB

func GetUserDB(userID string, username string) (*sql.DB, error)

GetUserDB retrieves the database connection for a specific user, creating it if it doesn't exist

func GetUsernameByID added in v0.1.8

func GetUsernameByID(userID string) (string, error)

GetUsernameByID retrieves username by user ID

func HandleActivity

func HandleActivity(c echo.Context) error

func HandleAnalytics added in v0.1.9

func HandleAnalytics(c echo.Context) error

HandleAnalytics returns analytics data for the Summary tab

func HandleCalls added in v0.1.3

func HandleCalls(c echo.Context) error

func HandleChangePassword

func HandleChangePassword(c echo.Context) error

func HandleConversations

func HandleConversations(c echo.Context) error

func HandleDateRange

func HandleDateRange(c echo.Context) error

func HandleGetSettings added in v0.1.7

func HandleGetSettings(c echo.Context) error

HandleGetSettings handles GET /api/settings

func HandleLogin

func HandleLogin(c echo.Context) error

func HandleLogout

func HandleLogout(c echo.Context) error

func HandleMe

func HandleMe(c echo.Context) error

func HandleMedia

func HandleMedia(c echo.Context) error

func HandleMediaItems added in v0.1.7

func HandleMediaItems(c echo.Context) error

HandleMediaItems returns only media (images/videos) for a conversation

func HandleMessages

func HandleMessages(c echo.Context) error

func HandleProgress

func HandleProgress(c echo.Context) error

func HandleRegister

func HandleRegister(c echo.Context) error

func HandleSearch

func HandleSearch(c echo.Context) error

func HandleUpdateSettings added in v0.1.7

func HandleUpdateSettings(c echo.Context) error

HandleUpdateSettings handles PUT /api/settings

func HandleUpload

func HandleUpload(c echo.Context) error

func HandleVersion added in v0.1.5

func HandleVersion(c echo.Context) error

HandleVersion returns the application version

func InitAuthDB

func InitAuthDB(filepath string) error

InitAuthDB initializes the authentication database

func InitDB

func InitDB(filepath string) error

func InitUserDB

func InitUserDB(userID string, filepath string) error

InitUserDB initializes a database for a specific user

func InsertCallLog

func InsertCallLog(userDB *sql.DB, call *CallLog) error

func InsertCallLogBatch

func InsertCallLogBatch(userDB *sql.DB, calls []CallLog) error

InsertCallLogBatch inserts multiple call logs in a single transaction for better performance

func InsertMessage

func InsertMessage(userDB *sql.DB, msg *Message) error

func NoCacheMiddleware

func NoCacheMiddleware(next echo.HandlerFunc) echo.HandlerFunc

NoCacheMiddleware adds cache control headers to prevent browser caching This ensures that dynamic API responses are always fetched fresh from the server

func ParseSMSBackupStreaming

func ParseSMSBackupStreaming(userDB *sql.DB, r io.Reader, batchSize int) (int, int, error)

ParseSMSBackupStreaming parses SMS backup file with streaming to reduce memory usage Each message is inserted immediately and memory is freed aggressively

func ProcessUploadedFile

func ProcessUploadedFile(userID string, username string, filePath string)

ProcessUploadedFile processes the uploaded file in the background

func SanitizeUsername

func SanitizeUsername(username string) string

SanitizeUsername converts a username to a safe filesystem name

func SaveUploadedFile

func SaveUploadedFile(file io.Reader, filename string) (string, error)

SaveUploadedFile saves the uploaded file to a temporary location

func SaveUserSettings added in v0.1.7

func SaveUserSettings(userID string, settings Settings) error

SaveUserSettings saves settings for a user

func SetUploadProgress

func SetUploadProgress(total, processed int, status string)

SetUploadProgress initializes or updates the upload progress

func UpdateCallProgress

func UpdateCallProgress(processed int)

UpdateCallProgress updates the progress for calls

func UpdateMessageProgress

func UpdateMessageProgress(processed int)

UpdateMessageProgress updates the progress for messages

func UpdatePassword

func UpdatePassword(userID string, newPassword string) error

UpdatePassword updates a user's password

func VerifyPassword

func VerifyPassword(user *User, password string) bool

VerifyPassword checks if the provided password matches the user's password hash

Types

type ActivityItem

type ActivityItem struct {
	Type        string    `json:"type"` // "message" or "call"
	Date        time.Time `json:"date"`
	Address     string    `json:"address"`
	ContactName string    `json:"contact_name,omitempty"`
	// Message-specific fields
	Message *Message `json:"message,omitempty"`
	// Call-specific fields
	Call *CallLog `json:"call,omitempty"`
}

func GetActivity

func GetActivity(userDB *sql.DB, startDate, endDate *time.Time, limit, offset int) ([]ActivityItem, error)

func GetActivityByAddress

func GetActivityByAddress(userDB *sql.DB, address string, startDate, endDate *time.Time, limit, offset int) ([]ActivityItem, error)

type AnalyticsResponse added in v0.1.9

type AnalyticsResponse struct {
	TotalMessages      int                  `json:"total_messages"`
	TotalSMS           int                  `json:"total_sms"`
	TotalMMS           int                  `json:"total_mms"`
	TotalCalls         int                  `json:"total_calls"`
	TotalSent          int                  `json:"total_sent"`
	TotalReceived      int                  `json:"total_received"`
	IncomingCalls      int                  `json:"incoming_calls"`
	OutgoingCalls      int                  `json:"outgoing_calls"`
	MissedCalls        int                  `json:"missed_calls"`
	TotalCallDuration  int                  `json:"total_call_duration"`
	AvgMessageLength   float64              `json:"avg_message_length"`
	TopContacts        []TopContact         `json:"top_contacts"`
	HourlyDistribution []HourlyDistribution `json:"hourly_distribution"`
	DailyTrend         []DailyCount         `json:"daily_trend"`
}

func GetAnalytics added in v0.1.9

func GetAnalytics(userDB *sql.DB, startDate, endDate *time.Time, topN int, tzOffsetMinutes int) (*AnalyticsResponse, error)

GetAnalytics retrieves analytics data for the Summary tab

type AuthResponse

type AuthResponse struct {
	Success bool     `json:"success"`
	User    *User    `json:"user,omitempty"`
	Session *Session `json:"session,omitempty"`
	Error   string   `json:"error,omitempty"`
}

type AutoImportService added in v0.1.8

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

AutoImportService manages automatic file imports for all users

func NewAutoImportService added in v0.1.8

func NewAutoImportService(dataDir string) *AutoImportService

NewAutoImportService creates a new auto-import service

func (*AutoImportService) Start added in v0.1.8

func (s *AutoImportService) Start()

Start begins the auto-import background job

func (*AutoImportService) Stop added in v0.1.8

func (s *AutoImportService) Stop()

Stop gracefully stops the auto-import service

type CallEntry

type CallEntry struct {
	Number         string `xml:"number,attr"`
	Duration       string `xml:"duration,attr"`
	Date           string `xml:"date,attr"`
	Type           string `xml:"type,attr"`
	Presentation   string `xml:"presentation,attr"`
	SubscriptionID string `xml:"subscription_id,attr"`
	ReadableDate   string `xml:"readable_date,attr"`
	ContactName    string `xml:"contact_name,attr"`
}

type CallLog

type CallLog struct {
	ID             int64     `json:"id"`
	Number         string    `json:"number"`
	Duration       int       `json:"duration"` // in seconds
	Date           time.Time `json:"date"`
	Type           int       `json:"type"`                   // 1 = incoming, 2 = outgoing, 3 = missed, 4 = voicemail, 5 = rejected, 6 = refused
	Presentation   int       `json:"presentation,omitempty"` // 1 = allowed, 2 = restricted, 3 = unknown, 4 = payphone
	SubscriptionID string    `json:"subscription_id,omitempty"`
	ContactName    string    `json:"contact_name,omitempty"`
}

func GetAllCalls added in v0.1.3

func GetAllCalls(userDB *sql.DB, startDate, endDate *time.Time, limit, offset int) ([]CallLog, error)

func GetCallLogs

func GetCallLogs(userDB *sql.DB, number string, startDate, endDate *time.Time) ([]CallLog, error)

type ChangePasswordRequest

type ChangePasswordRequest struct {
	OldPassword     string `json:"old_password"`
	NewPassword     string `json:"new_password"`
	ConfirmPassword string `json:"confirm_password"`
}

type Conversation

type Conversation struct {
	Address      string    `json:"address"`
	ContactName  string    `json:"contact_name,omitempty"`
	Subject      string    `json:"subject,omitempty"`
	LastMessage  string    `json:"last_message"`
	LastDate     time.Time `json:"last_date"`
	MessageCount int       `json:"message_count"`
	Type         string    `json:"type"` // "sms", "mms", or "call"
}

func GetConversations

func GetConversations(userDB *sql.DB, startDate, endDate *time.Time) ([]Conversation, error)

type ConversationSettings added in v0.1.7

type ConversationSettings struct {
	ShowCalls bool `json:"show_calls"`
}

ConversationSettings contains settings for the conversation view

type DailyCount added in v0.1.9

type DailyCount struct {
	Date  string `json:"date"`
	Count int    `json:"count"`
}

type HourlyDistribution added in v0.1.9

type HourlyDistribution struct {
	Hour  int `json:"hour"`
	Count int `json:"count"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type MMSAddr

type MMSAddr struct {
	Address string `xml:"address,attr"`
	Type    string `xml:"type,attr"`
	Charset string `xml:"charset,attr"`
}

type MMSEntry

type MMSEntry struct {
	Address      string    `xml:"address,attr"`
	Date         string    `xml:"date,attr"`
	Type         string    `xml:"msg_box,attr"`
	Read         string    `xml:"read,attr"`
	ThreadID     string    `xml:"thread_id,attr"`
	Subject      string    `xml:"sub,attr"`
	TrID         string    `xml:"tr_id,attr"`
	ContentType  string    `xml:"ct_t,attr"`
	ReadReport   string    `xml:"rr,attr"`
	ReadStatus   string    `xml:"read_status,attr"`
	MessageID    string    `xml:"m_id,attr"`
	MessageSize  string    `xml:"m_size,attr"`
	MessageType  string    `xml:"m_type,attr"`
	SimSlot      string    `xml:"sim_slot,attr"`
	ReadableDate string    `xml:"readable_date,attr"`
	ContactName  string    `xml:"contact_name,attr"`
	Parts        []MMSPart `xml:"parts>part"`
	Addrs        []MMSAddr `xml:"addrs>addr"`
	Body         string    `xml:"body,attr"`
}

type MMSPart

type MMSPart struct {
	Seq         string `xml:"seq,attr"`
	ContentType string `xml:"ct,attr"`
	Name        string `xml:"name,attr"`
	Charset     string `xml:"chset,attr"`
	CL          string `xml:"cl,attr"`
	Text        string `xml:"text,attr"`
	Data        string `xml:"data,attr"`
}

type Message

type Message struct {
	ID          int64     `json:"id"`
	Address     string    `json:"address"`
	Body        string    `json:"body"`
	Type        int       `json:"type"` // 1 = received, 2 = sent, 3 = draft, 4 = outbox, 5 = failed, 6 = queued
	Date        time.Time `json:"date"`
	Read        bool      `json:"read"`
	ThreadID    int       `json:"thread_id"`
	Subject     string    `json:"subject,omitempty"`
	MediaType   string    `json:"media_type,omitempty"`
	MediaData   []byte    `json:"-"`
	MediaBase64 string    `json:"media_base64,omitempty"`
	// Additional SMS fields
	Protocol      int    `json:"protocol,omitempty"`
	Status        int    `json:"status,omitempty"` // -1 = none, 0 = complete, 32 = pending, 64 = failed
	ServiceCenter string `json:"service_center,omitempty"`
	SubID         int    `json:"sub_id,omitempty"`
	ContactName   string `json:"contact_name,omitempty"`
	Sender        string `json:"sender,omitempty"` // Sender phone number for received messages
	// Additional MMS fields
	ContentType string   `json:"content_type,omitempty"` // ct_t field
	ReadReport  int      `json:"read_report,omitempty"`  // rr field
	ReadStatus  int      `json:"read_status,omitempty"`
	MessageID   string   `json:"message_id,omitempty"`   // m_id field
	MessageSize int      `json:"message_size,omitempty"` // m_size field
	MessageType int      `json:"message_type,omitempty"` // m_type field
	SimSlot     int      `json:"sim_slot,omitempty"`
	Addresses   []string `json:"addresses,omitempty"` // All phone numbers in conversation (for MMS)
}

func GetMediaByAddress added in v0.1.7

func GetMediaByAddress(userDB *sql.DB, address string, startDate, endDate *time.Time) ([]Message, error)

GetMediaByAddress fetches only media items (images/videos) for a specific address

func GetMessages

func GetMessages(userDB *sql.DB, address string, startDate, endDate *time.Time) ([]Message, error)

type ParseResult

type ParseResult struct {
	Messages []Message
	Calls    []CallLog
}

func ParseSMSBackup

func ParseSMSBackup(r io.Reader) (ParseResult, error)

type RegisterRequest

type RegisterRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type SMSBackup

type SMSBackup struct {
	XMLName  xml.Name    `xml:"smses"`
	Count    int         `xml:"count,attr"`
	Messages []SMSEntry  `xml:"sms"`
	MMS      []MMSEntry  `xml:"mms"`
	Calls    []CallEntry `xml:"call"`
}

type SMSEntry

type SMSEntry struct {
	Address       string `xml:"address,attr"`
	Date          string `xml:"date,attr"`
	Type          string `xml:"type,attr"`
	Body          string `xml:"body,attr"`
	Read          string `xml:"read,attr"`
	ThreadID      string `xml:"thread_id,attr"`
	Subject       string `xml:"subject,attr"`
	Protocol      string `xml:"protocol,attr"`
	TOA           string `xml:"toa,attr"`
	SCTOA         string `xml:"sc_toa,attr"`
	ServiceCenter string `xml:"service_center,attr"`
	Status        string `xml:"status,attr"`
	SubID         string `xml:"sub_id,attr"`
	ReadableDate  string `xml:"readable_date,attr"`
	ContactName   string `xml:"contact_name,attr"`
}

type SearchResult

type SearchResult struct {
	MessageID   int64     `json:"message_id"`
	Address     string    `json:"address"`
	ContactName string    `json:"contact_name"`
	Body        string    `json:"body"`
	Date        time.Time `json:"date"`
	Snippet     string    `json:"snippet"`
}

SearchResult represents a message search result

func SearchMessages

func SearchMessages(userDB *sql.DB, query string, limit int) ([]SearchResult, error)

SearchMessages performs full-text search on message contents

type Session

type Session struct {
	ID        string    `json:"id"`
	UserID    string    `json:"user_id"`
	Username  string    `json:"username"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

func CreateSession

func CreateSession(userID string, username string) (*Session, error)

CreateSession creates a new session for a user

func GetSession

func GetSession(sessionID string) (*Session, error)

GetSession retrieves a session by ID

type Settings added in v0.1.7

type Settings struct {
	Conversations ConversationSettings `json:"conversations"`
}

Settings represents user settings stored as JSON

func GetDefaultSettings added in v0.1.7

func GetDefaultSettings() Settings

GetDefaultSettings returns the default settings

func GetUserSettings added in v0.1.7

func GetUserSettings(userID string) (Settings, error)

GetUserSettings retrieves settings for a user

type TopContact added in v0.1.9

type TopContact struct {
	Address       string `json:"address"`
	ContactName   string `json:"contact_name,omitempty"`
	MessageCount  int    `json:"message_count"`
	SentCount     int    `json:"sent_count"`
	ReceivedCount int    `json:"received_count"`
}

type UploadProgress

type UploadProgress struct {
	TotalMessages     int       `json:"total_messages"`
	ProcessedMessages int       `json:"processed_messages"`
	TotalCalls        int       `json:"total_calls"`
	ProcessedCalls    int       `json:"processed_calls"`
	Status            string    `json:"status"` // "parsing", "importing", "completed", "error"
	ErrorMessage      string    `json:"error_message,omitempty"`
	StartTime         time.Time `json:"start_time"`
	// contains filtered or unexported fields
}

UploadProgress tracks the progress of an ongoing upload

func GetUploadProgress

func GetUploadProgress() *UploadProgress

GetUploadProgress returns the current upload progress

type UploadResponse

type UploadResponse struct {
	Success      bool   `json:"success"`
	MessageCount int    `json:"message_count"`
	CallLogCount int    `json:"call_log_count"`
	Processing   bool   `json:"processing,omitempty"`
	Error        string `json:"error,omitempty"`
}

type User

type User struct {
	ID           string    `json:"id"`
	Username     string    `json:"username"`
	PasswordHash string    `json:"-"` // Never send password hash to client
	CreatedAt    time.Time `json:"created_at"`
}

func CreateUser

func CreateUser(username, password string) (*User, error)

CreateUser creates a new user with hashed password

func GetUserByUsername

func GetUserByUsername(username string) (*User, error)

GetUserByUsername retrieves a user by username

func ListUsers added in v0.1.8

func ListUsers() ([]User, error)

ListUsers returns all users in the database

Jump to

Keyboard shortcuts

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