smsmap

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package smsmap provides pure functions that map raw SMS and call-log fields to model.Document. It is shared by SMSCollector (XML backup parser) and the POST /api/v1/ingest/messages HTTP handler so that both sources produce structurally identical documents from the same input.

All functions are stateless and safe for concurrent use.

Index

Constants

View Source
const PIIRedactionToken = "[REDACTED]"

PIIRedactionToken is the placeholder inserted in place of detected structured PII. It matches the existing SMS OTP-redaction convention (see otpDigitsRe usage in MapSMS) so every source (SMS, call transcripts) surfaces the same redaction marker downstream.

Variables

This section is empty.

Functions

func BodyShortHash

func BodyShortHash(body string) string

BodyShortHash returns an 8-character hex string of SHA-256(body) used to disambiguate SourceIDs when two messages share the same address and millisecond timestamp. Exported for use in tests that need to compute expected SourceIDs.

func MapCall

func MapCall(number string, dateMs int64, durationSec int, typ int, contactName string) model.Document

MapCall maps raw call-log fields to a model.Document.

SourceID format: call-log:{dateMs}:{sha256(number)[:16]}:{sha256(durationStr)[:8]} Phone numbers (number) are hashed so raw PII is not stored in the SourceID. OccurredAt is time.UnixMilli(dateMs).UTC().

Parameters mirror the SMS Backup & Restore XML <call> element attributes and the POST /api/v1/ingest/messages JSON schema:

  • number: phone number (will be hashed in SourceID)
  • dateMs: Unix millisecond timestamp of the call
  • durationSec: call duration in seconds
  • typ: SMS Backup & Restore call type code (1=incoming, 2=outgoing, 3=missed, 4=voicemail, 5=rejected, 6=blocked)
  • contactName: display name of the contact (may be empty; falls back to number)

func MapSMS

func MapSMS(addr, body string, dateMs int64, typ int, contactName string) model.Document

MapSMS maps raw SMS fields to a model.Document.

SourceID format: sms:{dateMs}:{sha256(addr)[:16]}:{direction} Phone numbers (addr) are hashed so raw PII is not stored in the SourceID. direction (received/sent/draft/…) replaces the old bodyHash discriminator so that the SourceID is stable across body edits — enabling ON CONFLICT UPDATE (upsert) to overwrite content rather than inserting a duplicate document. Two messages from the same address at the same millisecond with different directions (e.g. a simultaneous inbound + outbound) are still uniquely identified because the direction segment differs. Auth-like bodies have their OTP digit runs replaced with [REDACTED]. OccurredAt is time.UnixMilli(dateMs).UTC().

Parameters mirror the SMS Backup & Restore XML <sms> element attributes and the POST /api/v1/ingest/messages JSON schema:

  • addr: phone number / address (will be hashed in SourceID)
  • body: message body (auth OTPs are redacted)
  • dateMs: Unix millisecond timestamp of the message
  • typ: SMS Backup & Restore type code (1=received, 2=sent, 3=draft, 4=outbox, 5=failed, 6=queued)
  • contactName: display name of the contact (may be empty; falls back to addr)

func RedactPII added in v0.21.2

func RedactPII(s string) string

RedactPII replaces structured, regex-detectable PII in s with PIIRedactionToken:

  • Korean resident registration numbers (RRN): \d{6}-\d{7}, plausibility- checked (see redactRRNIfPlausible).
  • Korean phone numbers (digit form only — see koreanPhoneRe).
  • Bank-account-like hyphenated digit runs (see bankAccountRe).
  • OTP/auth codes: 4-8 digit runs (the same pattern MapSMS uses) that appear near an authentication keyword (see redactAuthContextDigits).

Scope (issue #163, this release): regex-based structured PII only. Spoken-form phone numbers (e.g. "공일공에…") and NER-based name redaction are explicitly OUT of scope and deferred to a follow-up — both would require either a large hand-written grammar or a model/NER dependency, neither of which this pass introduces.

Order matters: RRN and phone patterns run before the bank-account pattern so that, e.g., a phone number's "010-1234-5678" hyphenated groups are already replaced with PIIRedactionToken (no longer digits) by the time the (structurally similar, 3-hyphenated-group) bank-account pattern runs, avoiding a confusing double-match. The OTP/auth pass runs last since it operates on whatever raw digit runs remain.

func ShortHash

func ShortHash(s string) string

ShortHash returns a 16-character hex string that is the first 8 bytes of SHA-256(s). Used to hash PII (phone numbers/addresses) in SourceIDs so they are not logged downstream. Exported for use in tests that need to compute expected SourceIDs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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