diff options
author | 2020-06-24 19:30:08 +0200 | |
---|---|---|
committer | 2020-06-24 19:30:08 +0200 | |
commit | 6e09d1b276002c87b0a1b5669c5c8fbbc191ba8f (patch) | |
tree | 5814c66024bedc717c786f2c0630899104e61308 | |
parent | Fix the InReplyTo reference (diff) | |
download | archives-6e09d1b276002c87b0a1b5669c5c8fbbc191ba8f.tar.gz archives-6e09d1b276002c87b0a1b5669c5c8fbbc191ba8f.tar.bz2 archives-6e09d1b276002c87b0a1b5669c5c8fbbc191ba8f.zip |
Rename MessageId to MessageIdField
Unfortunately the name MessageId conflicts with
go-pgs many2many relationship. That's why
MessageId has been renamed to MessageIdField.
However, a convenience method MessageId() has
been added for backwards compability in templates.
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r-- | pkg/database/connection.go | 2 | ||||
-rw-r--r-- | pkg/importer/utils.go | 12 | ||||
-rw-r--r-- | pkg/models/message.go | 12 |
3 files changed, 17 insertions, 9 deletions
diff --git a/pkg/database/connection.go b/pkg/database/connection.go index 1163679..4f7353c 100644 --- a/pkg/database/connection.go +++ b/pkg/database/connection.go @@ -69,6 +69,8 @@ func Connect() { DBCon.AddQueryHook(dbLogger{}) + orm.RegisterTable((*models.MessageToReferences)(nil)) + err := CreateSchema() if err != nil { // logger.Error.Println("ERROR: Could not create database schema") diff --git a/pkg/importer/utils.go b/pkg/importer/utils.go index 026ba41..ab9072f 100644 --- a/pkg/importer/utils.go +++ b/pkg/importer/utils.go @@ -54,7 +54,7 @@ func initImport(path string, info os.FileInfo, err error) error { From: m.Header.Get("From"), To: strings.Split(m.Header.Get("To"), ","), Subject: m.Header.Get("Subject"), - MessageId: m.Header.Get("Message-Id"), + MessageIdField: m.Header.Get("Message-Id"), }) } return nil @@ -83,7 +83,7 @@ func importIntoDatabase(path, filename string, m *mail.Message) { bodyContent, attachments := parseBody(m) msg := models.Message{ Id: m.Header.Get("X-Archives-Hash"), - MessageId: m.Header.Get("Message-Id"), + MessageIdField: m.Header.Get("Message-Id"), Filename: filename, From: m.Header.Get("From"), To: parseAddressList(m.Header.Get("To")), @@ -127,13 +127,13 @@ func parseAddressList(addressList string) []string { func getInReplyToMail(messageId, from string) string { // step 1 TODO add description for _, mail := range mails { - if mail.MessageId == messageId && strings.Contains(strings.Join(mail.To, ", "), from) { + if mail.MessageId() == messageId && strings.Contains(strings.Join(mail.To, ", "), from) { return mail.Id } } // step 2 TODO add description for _, mail := range mails { - if mail.MessageId == messageId { + if mail.MessageId() == messageId { return mail.Id } } @@ -146,13 +146,13 @@ func insertReferencesToMail(references []string, messageId, from string) []*mode for _, reference := range references { // step 1 TODO add description for _, mail := range mails { - if mail.MessageId == reference && strings.Contains(strings.Join(mail.To, ", "), from) { + if mail.MessageId() == reference && strings.Contains(strings.Join(mail.To, ", "), from) { referencesToMail = append(referencesToMail, mail) } } // step 2 TODO add description for _, mail := range mails { - if mail.MessageId == reference { + if mail.MessageId() == reference { referencesToMail = append(referencesToMail, mail) } } diff --git a/pkg/models/message.go b/pkg/models/message.go index 70c4e8f..e769319 100644 --- a/pkg/models/message.go +++ b/pkg/models/message.go @@ -8,8 +8,10 @@ import ( ) type Message struct { + tableName struct{} `pg:",discard_unknown_columns"` + Id string `pg:",pk"` - MessageId string + MessageIdField string Filename string List string @@ -61,6 +63,10 @@ type MessageToReferences struct { ReferenceId string } +func (m Message) MessageId() string { + return m.MessageIdField +} + func (m Message) GetListNameFromSubject() string { subject := m.Subject listName := strings.Split(subject, "]")[0] @@ -90,7 +96,7 @@ func (m Message) GetSubject() string { } func (m Message) GetMessageId() string { - messageId := m.MessageId + messageId := m.MessageIdField messageId = strings.ReplaceAll(messageId, "<", "") messageId = strings.ReplaceAll(messageId, ">", "") messageId = strings.ReplaceAll(messageId, "\"", "") @@ -98,7 +104,7 @@ func (m Message) GetMessageId() string { } func (m Message) GetInReplyTo() string { - inReplyTo := m.InReplyTo.MessageId + inReplyTo := m.InReplyTo.MessageIdField inReplyTo = strings.ReplaceAll(inReplyTo, "<", "") inReplyTo = strings.ReplaceAll(inReplyTo, ">", "") inReplyTo = strings.ReplaceAll(inReplyTo, " ", "") |