smsbackuprestore

package
v0.0.0-...-e25cbd9 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package smsbackuprestore contains types, type methods, and functions for parsing SMS Backup & Restore Android app XML output and generating delimited data and decoding images from MMS messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupMessageBody

func CleanupMessageBody(body string) string

CleanupMessageBody removes newlines and tabs from strings.

func DecodeImages

func DecodeImages(m *Messages, mainOutputDir string) (numImagesIdentified, numImagesSuccessfullyWritten int, errors []error)

DecodeImages identifies base64-encoded images in backed-up MMS messages and decodes them and outputs them to files with a unique file name tied to the MMS and part index numbers.

func GenerateCallOutput

func GenerateCallOutput(c *Calls, outputDir string) error

GenerateCallOutput outputs a tab-delimited file named "calls.tsv" containing parsed calls from the backup file.

func GenerateMMSOutput

func GenerateMMSOutput(m *Messages, outputDir string) error

GenerateMMSOutput outputs a tab-delimited file named "mms.tsv" containing parsed MMS messages from the backup file.

func GenerateSMSOutput

func GenerateSMSOutput(m *Messages, outputDir string) error

GenerateSMSOutput outputs a tab-delimited file named "sms.tsv" containing parsed SMS messages from the backup file.

func GetFileExtensionFromContentType

func GetFileExtensionFromContentType(contentType string) string

GetFileExtensionFromContentType determines the file extension of the base64-encoded file based on the content type.

func NormalizePhoneNumber

func NormalizePhoneNumber(number string) string

NormalizePhoneNumber attempts to normalize phone numbers in the format 13125551212, ignoring input with multiple numbers delimited by a tilde ('~') character.

func RemoveCommasBeforeSuffixes

func RemoveCommasBeforeSuffixes(contacts string) string

RemoveCommasBeforeSuffixes recursively strips commas before suffixes such as M.D. to prevent contact names from being split by a comma in the middle of a name and suffix.

The list is by no means comprehensive but includes the following common suffixes: - MD - DO - NP - RN - JR - SR - II - III - INC - LLP - LLC - LPN - ACSW - LCSW - MA - PHD

func ReplaceAllBytesSubmatchFunc

func ReplaceAllBytesSubmatchFunc(re *regexp.Regexp, b []byte, repl func([][]byte) []byte) []byte

ReplaceAllBytesSubmatchFunc replaces all bytes in the byte slice that match the specified pattern.

This is being done in an attempt to render emoji's properly due to SMS Backup & Restore app rendering of emoji's as HTML entitites in decimal (SLOW).

Function is based on http://elliot.land/post/go-replace-string-with-regular-expression-callback

Types

type Address

type Address struct {
	XMLName xml.Name    `xml:"addr"`
	Address PhoneNumber `xml:"address,string,attr"`
}

type AndroidTS

type AndroidTS string

func (AndroidTS) String

func (timestamp AndroidTS) String() string

String method for AndroidTS type converts string representing milliseconds since the Unix epoch into a human-readable timestamp in UTC time zone.

type BoolValue

type BoolValue int

func (BoolValue) String

func (bv BoolValue) String() string

String method for BoolValue type converts integer/boolean into human-readable boolean value (true/false).

type Call

type Call struct {
	XMLName      xml.Name    `xml:"call"`
	Number       PhoneNumber `xml:"number,string,attr"`
	Duration     int         `xml:"duration,string,attr"`
	Date         AndroidTS   `xml:"date,string,attr"` // consider reading in as int
	Type         CallType    `xml:"type,string,attr"`
	ReadableDate string      `xml:"readable_date,attr"`
	ContactName  string      `xml:"contact_name,attr"`
}

type CallType

type CallType int

func (CallType) String

func (ct CallType) String() string

String method for CallType type converts integer to human-readable status

See http://synctech.com.au/wp-content/uploads/2017/12/calls.xsl

Type: 1 = Incoming, 2 = Outgoing, 3 = Missed, 4 = Voicemail, 5 = Rejected, 6 = Refused List

type Calls

type Calls struct {
	XMLName    xml.Name  `xml:"calls"`
	Count      string    `xml:"count,attr"`
	BackupSet  string    `xml:"backup_set,attr"`
	BackupDate AndroidTS `xml:"backup_date,string,attr"`
	Calls      []Call    `xml:"call"`
}

func (*Calls) PrintCallCountQC

func (c *Calls) PrintCallCountQC()

PrintCallCountQC performs basic count validation and prints the results to stdout.

type MMS

type MMS struct {
	XMLName           xml.Name    `xml:"mms"`
	TextOnly          BoolValue   `xml:"text_only,string,attr"`
	Read              ReadStatus  `xml:"read,string,attr"`
	Date              AndroidTS   `xml:"date,string,attr"` // consider reading in as int
	Locked            BoolValue   `xml:"locked,string,attr"`
	DateSent          AndroidTS   `xml:"date_sent,string,attr"`
	ReadableDate      string      `xml:"readable_date,attr"`
	ContactName       string      `xml:"contact_name,attr"`
	Seen              BoolValue   `xml:"seen,string,attr"`
	FromAddress       PhoneNumber `xml:"from_address,string,attr"`
	Address           PhoneNumber `xml:"address,string,attr"`
	MessageClassifier string      `xml:"m_cls,attr"`
	MessageSize       string      `xml:"m_size,attr"`
	Parts             []Part      `xml:"parts>part"`
	Addresses         []Address   `xml:"addrs>addr"`
}

type Messages

type Messages struct {
	XMLName    xml.Name  `xml:"smses"`
	Count      string    `xml:"count,attr"`
	BackupSet  string    `xml:"backup_set,attr"`
	BackupDate AndroidTS `xml:"backup_date,string,attr"`
	SMS        []SMS     `xml:"sms"`
	MMS        []MMS     `xml:"mms"`
}

func (*Messages) PrintMessageCountQC

func (m *Messages) PrintMessageCountQC()

PrintMessageCountQC performs basic count validation and prints the results to stdout.

type Part

type Part struct {
	XMLName        xml.Name `xml:"part"`
	ContentType    string   `xml:"ct,attr"`
	Name           string   `xml:"name,attr"`
	FileName       string   `xml:"fn,attr"`
	ContentDisplay string   `xml:"cd,attr"`
	Text           string   `xml:"text,attr"`
	Base64Data     string   `xml:"data,attr"`
}

func (Part) DecodeAndWriteImage

func (p Part) DecodeAndWriteImage(outputPath string) error

DecodeAndWriteImage decodes and writes base64-encoded image to file output path specified as parameter.

func (Part) ImageFileName

func (p Part) ImageFileName(mmsIndex int, partIndex int) string

ImageFileName method for Part type determines file name of base64-encoded image given Part and MMS and Part indices.

type PhoneNumber

type PhoneNumber string

func (PhoneNumber) String

func (p PhoneNumber) String() string

String method for PhoneNumber type attempts to normalize phone number by calling NormalizePhoneNumber().

type ReadStatus

type ReadStatus int

func (ReadStatus) String

func (rs ReadStatus) String() string

String method for ReadStatus type converts integer/boolean to human-readable read status

See http://synctech.com.au/fields-in-xml-backup-files/

Read: Read Message = 1, Unread Message = 0

type SMS

type SMS struct {
	XMLName       xml.Name       `xml:"sms"`
	Protocol      string         `xml:"protocol,attr"`
	Address       PhoneNumber    `xml:"address,string,attr"`
	Type          SMSMessageType `xml:"type,string,attr"`
	Subject       string         `xml:"subject,attr"`
	Body          string         `xml:"body,attr"`
	ServiceCenter PhoneNumber    `xml:"service_center,string,attr"`
	Status        SMSStatus      `xml:"status,string,attr"`
	Read          ReadStatus     `xml:"read,string,attr"`
	Date          AndroidTS      `xml:"date,string,attr"` // consider reading in as int
	Locked        BoolValue      `xml:"locked,string,attr"`
	DateSent      AndroidTS      `xml:"date_sent,string,attr"`
	ReadableDate  string         `xml:"readable_date,attr"`
	ContactName   string         `xml:"contact_name,attr"`
}

type SMSMessageType

type SMSMessageType int

func (SMSMessageType) String

func (smt SMSMessageType) String() string

String method for SMSMessageType type converts integer to human-readable message type

See http://synctech.com.au/fields-in-xml-backup-files/

Type: 1 = Received, 2 = Sent, 3 = Draft, 4 = Outbox, 5 = Failed, 6 = Queued

type SMSStatus

type SMSStatus int

func (SMSStatus) String

func (ss SMSStatus) String() string

String method for SMSStatus type converts integer to human-readable status

See http://synctech.com.au/fields-in-xml-backup-files/

Status: None = -1, Complete = 0, Pending = 32, Failed = 64

Jump to

Keyboard shortcuts

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