Skip to content

Commit

Permalink
Add NETMAIL address in storage #93
Browse files Browse the repository at this point in the history
  • Loading branch information
vit1251 committed Nov 3, 2020
1 parent 297f4b0 commit 2ec7b77
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 16 deletions.
24 changes: 24 additions & 0 deletions pkg/installer/Migration_20201103033800.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package installer

import "database/sql"

func migration_20201103033800_Up(conn *sql.DB) error {

/* Add "nmOrigAddr" */
query1 := "ALTER TABLE `netmail` ADD `nmOrigAddr` varchar(64) DEFAULT ''"
if _, err := conn.Exec(query1); err != nil {
return err
}

/* Add "nmOrigAddr" */
query2 := "ALTER TABLE `netmail` ADD `nmDestAddr` varchar(64) DEFAULT ''"
if _, err := conn.Exec(query2); err != nil {
return err
}

return nil
}

func init() {
migrations.Set("2020-11-03 03:38:00", nil, migration_20201103033800_Up)
}
22 changes: 16 additions & 6 deletions pkg/netmail/NetmailManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (self *NetmailManager) GetMessageHeaders() ([]*NetmailMessage, error) {

var result []*NetmailMessage

query1 := "SELECT `nmId`, `nmHash`, `nmSubject`, `nmViewCount`, `nmFrom`, `nmTo`, `nmDate` FROM `netmail` ORDER BY `nmDate` ASC, `nmId` ASC"
query1 := "SELECT `nmId`, `nmHash`, `nmSubject`, `nmViewCount`, `nmFrom`, `nmTo`, `nmOrigAddr`, `nmDestAddr`, `nmDate` FROM `netmail` ORDER BY `nmDate` ASC, `nmId` ASC"
var params []interface{}

storageManager.Query(query1, params, func(rows *sql.Rows) error {
Expand All @@ -33,10 +33,12 @@ func (self *NetmailManager) GetMessageHeaders() ([]*NetmailMessage, error) {
var subject string
var from string
var to string
var origAddr string
var destAddr string
var msgDate int64
var viewCount int

err2 := rows.Scan(&ID, &msgHash, &subject, &viewCount, &from, &to, &msgDate)
err2 := rows.Scan(&ID, &msgHash, &subject, &viewCount, &from, &to, &origAddr, &destAddr, &msgDate)
if err2 != nil{
return err2
}
Expand All @@ -52,6 +54,8 @@ func (self *NetmailManager) GetMessageHeaders() ([]*NetmailMessage, error) {
msg.SetTo(to)
msg.SetUnixTime(msgDate)
msg.SetViewCount(viewCount)
msg.SetOrigAddr(origAddr)
msg.SetDestAddr(destAddr)

result = append(result, msg)

Expand All @@ -66,9 +70,9 @@ func (self *NetmailManager) Write(msg *NetmailMessage) error {
storageManager := self.restoreStorageManager()

query1 := "INSERT INTO `netmail` " +
"(nmMsgId, nmHash, nmFrom, nmTo, nmSubject, nmBody, nmDate) " +
"(nmMsgId, nmHash, nmFrom, nmTo, nmSubject, nmBody, nmDate, nmOrigAddr, nmDestAddr) " +
"VALUES " +
"(?, ?, ?, ?, ?, ?, ?)"
"(?, ?, ?, ?, ?, ?, ?, ?, ?)"
var params []interface{}
params = append(params, msg.MsgID)
params = append(params, msg.Hash)
Expand All @@ -77,6 +81,8 @@ func (self *NetmailManager) Write(msg *NetmailMessage) error {
params = append(params, msg.Subject)
params = append(params, msg.Content)
params = append(params, msg.UnixTime)
params = append(params, msg.OrigAddr)
params = append(params, msg.DestAddr)

err1 := storageManager.Exec(query1, params, func(result sql.Result, err error) error {
return nil
Expand All @@ -91,7 +97,7 @@ func (self *NetmailManager) GetMessageByHash(msgHash string) (*NetmailMessage, e

var result *NetmailMessage

query1 := "SELECT `nmId`, `nmHash`, `nmSubject`, `nmViewCount`, `nmFrom`, `nmTo`, `nmDate`, `nmBody` FROM `netmail` WHERE `nmHash` = ?"
query1 := "SELECT `nmId`, `nmHash`, `nmSubject`, `nmViewCount`, `nmFrom`, `nmTo`, `nmDate`, `nmBody`, `nmOrigAddr`, `nmDestAddr` FROM `netmail` WHERE `nmHash` = ?"
var params []interface{}
params = append(params, msgHash)

Expand All @@ -105,8 +111,10 @@ func (self *NetmailManager) GetMessageByHash(msgHash string) (*NetmailMessage, e
var body string
var msgDate int64
var viewCount int
var origAddr string
var destAddr string

err2 := rows.Scan(&ID, &msgHash, &subject, &viewCount, &from, &to, &msgDate, &body)
err2 := rows.Scan(&ID, &msgHash, &subject, &viewCount, &from, &to, &msgDate, &body, &origAddr, &destAddr)
if err2 != nil{
return err2
}
Expand All @@ -123,6 +131,8 @@ func (self *NetmailManager) GetMessageByHash(msgHash string) (*NetmailMessage, e
msg.SetUnixTime(msgDate)
msg.SetViewCount(viewCount)
msg.SetContent(body)
msg.SetOrigAddr(origAddr)
msg.SetDestAddr(destAddr)

result = msg

Expand Down
10 changes: 10 additions & 0 deletions pkg/netmail/NetmailMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type NetmailMessage struct {
Hash string
From string
To string
OrigAddr string
DestAddr string
Subject string
Content string
UnixTime int64
Expand Down Expand Up @@ -82,3 +84,11 @@ func (self *NetmailMessage) SetPacket(packet []byte) {
self.Packet = packet
}

func (self *NetmailMessage) SetOrigAddr(addr string) {
self.OrigAddr = addr
}

func (self *NetmailMessage) SetDestAddr(addr string) {
self.DestAddr = addr
}

6 changes: 3 additions & 3 deletions pkg/site/action/FileAreaComposeCompleteAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type FileAreaComposeCompleteAction struct {
Action
}

func NewFileAreaComposeCompleteAction() *FileAreaComposeAction {
return new(FileAreaComposeAction)
func NewFileAreaComposeCompleteAction() *FileAreaComposeCompleteAction {
return new(FileAreaComposeCompleteAction)
}

func (self *FileAreaComposeCompleteAction) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (self FileAreaComposeCompleteAction) ServeHTTP(w http.ResponseWriter, r *http.Request) {

//fileArea := "NASA"

Expand Down
2 changes: 1 addition & 1 deletion pkg/site/action/NetmailReplyAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (self *NetmailReplyAction) ServeHTTP(w http.ResponseWriter, r *http.Request
}

msgFrom := origMsg.From
msgFromAddr := "" // origMsg.FromAddr
msgFromAddr := fmt.Sprintf("%s", origMsg.OrigAddr)
newBody := self.preprocessMessage(origMsg)

/* Compact header*/
Expand Down
16 changes: 14 additions & 2 deletions pkg/site/action/NetmailViewAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,29 @@ func (self NetmailViewAction) makeMessageHeaderSection(origMsg *netmail.NetmailM
SetClass("netmail-msg-view-header")

/* Make "From" section */
var msgFrom string
if origMsg.OrigAddr == "" {
msgFrom = fmt.Sprintf("%s", origMsg.From)
} else {
msgFrom = fmt.Sprintf("%s (%s)", origMsg.From, origMsg.OrigAddr)
}
self.makeMessageHeaderRowSection(
headerTable,
widgets.NewTextWidgetWithText("From:"),
widgets.NewTextWidgetWithText(origMsg.From),
widgets.NewTextWidgetWithText(msgFrom),
)

/* Make "To" section */
var msgTo string
if origMsg.DestAddr == "" {
msgTo = fmt.Sprintf("%s", origMsg.To)
} else {
msgTo = fmt.Sprintf("%s (%s)", origMsg.To, origMsg.DestAddr)
}
self.makeMessageHeaderRowSection(
headerTable,
widgets.NewTextWidgetWithText("To:"),
widgets.NewTextWidgetWithText(origMsg.To),
widgets.NewTextWidgetWithText(msgTo),
)

/* Make "Subject" section */
Expand Down
9 changes: 5 additions & 4 deletions pkg/tosser/Tosser_Inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ func (self *Tosser) processNewDirectMessage(msgHeader *packet.PacketMessageHeade
/* Populate message */
newMsg := netmail.NewNetmailMessage()

newMsg.SetFrom(string(newFrom))
newMsg.SetTo(string(newTo))
newMsg.SetSubject(string(newSubject))
newMsg.SetFrom(newFrom)
newMsg.SetTo(newTo)
newMsg.SetSubject(newSubject)
newMsg.SetTime(msgTime)
newMsg.SetMsgID(msgID)
newMsg.SetHash(msgHash)
//newMsg.SetPacket(msgBody.RAW)
newMsg.SetOrigAddr(msgHeader.OrigAddr.String())
newMsg.SetDestAddr(msgHeader.DestAddr.String())

/* Decode message body */
msgContent := msgBody.GetContent()
Expand Down

0 comments on commit 2ec7b77

Please sign in to comment.