smsmap

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 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, numberHashingEnabled bool, nameRedactionEnabled ...bool) 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. This hashing is UNCONDITIONAL — independent of numberHashingEnabled — since changing the SourceID scheme would orphan every already-ingested document (see the numberHashingEnabled parameter doc below for why that's out of scope for this flag). 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)
  • numberHashingEnabled: issue #164's phone-number hashing policy flag (cfg.PIINumberHashingEnabled). Does NOT affect the SourceID (see above). Controls two things: 1. The anonymous-caller (empty contactName) Title/Content fallback: true reproduces the original #164 behaviour byte-for-byte (a one-way hashed label, "상대 " + numHash[:8]); false falls back to the raw number instead. 2. Metadata["number"]: present with the raw number when false (this is the point of disabling hashing — the number becomes searchable/ visible); absent entirely when true, matching pre-existing metadata shape.

func MapSMS

func MapSMS(addr, body string, dateMs int64, typ int, contactName string, numberHashingEnabled bool, nameRedactionEnabled ...bool) 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. This hashing is UNCONDITIONAL — independent of numberHashingEnabled — since changing the SourceID scheme would orphan every already-ingested document (see the numberHashingEnabled parameter doc below for why that's out of scope for this flag). 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]. This OTP redaction is a distinct mechanism from smsmap.RedactPII / issue #163's PIIRedactionEnabled flag and is NOT gated by it — it targets short-lived authentication codes rather than structured personal-identity PII, and remains unconditional regardless of PII_REDACTION_ENABLED. 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)
  • numberHashingEnabled: issue #164's phone-number hashing policy flag (cfg.PIINumberHashingEnabled). Does NOT affect the SourceID (see above). When false (the default), the raw address is additionally written into Metadata["number"] so it is searchable/visible — this is the point of disabling hashing; when true, Metadata carries no number field at all, matching the pre-existing (pre-this-change) behaviour byte-for-byte.

func RedactKnownContact added in v0.23.0

func RedactKnownContact(doc *model.Document)

RedactKnownContact masks known fields consistently without changing dedup identity. This is not NER: unknown names in free text require the API pass.

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, domestic trunk-prefix form (see koreanPhoneRe) and international country-code form — with/without "+"/"0082", and with hyphen/space/dot separators (see koreanPhoneIntlPlusRe, koreanPhoneIntl00Re, koreanPhoneIntlBareRe).
  • 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.

Scope (issue #167): only Korean (+82) country-code digit-form numbers are covered. Other countries' international numbers (e.g. "+1-...") are out of scope and are left untouched by these patterns — they simply don't match the literal "82"/"+82"/"0082" markers required here.

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