Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions models/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ type Thread struct {

// SHA256 hash of the raw subject without prefixes
SubjectHash string `json:"subject_hash" gorethink:"subject_hash"`

// all, some, none
Secure string `json:"secure" gorethink:"secure"`
}
29 changes: 28 additions & 1 deletion routes/emails.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func EmailsCreate(c web.C, w http.ResponseWriter, r *http.Request) {
// Check if Thread is set
if input.Thread != "" {
// todo: make it an actual exists check to reduce lan bandwidth
_, err := env.Threads.GetThread(input.Thread)
thread, err := env.Threads.GetThread(input.Thread)
if err != nil {
env.Log.WithFields(logrus.Fields{
"id": input.Thread,
Expand All @@ -253,16 +253,43 @@ func EmailsCreate(c web.C, w http.ResponseWriter, r *http.Request) {
})
return
}

// update thread.secure depending on email's kind
if (input.Kind == "raw" && thread.Secure == "all") ||
(input.Kind == "manifest" && thread.Secure == "none") ||
(input.Kind == "pgpmime" && thread.Secure == "none") {
if err := env.Threads.UpdateID(thread.ID, map[string]interface{}{
"secure": "some",
}); err != nil {
env.Log.WithFields(logrus.Fields{
"id": input.Thread,
"error": err.Error(),
}).Warn("Cannot update a thread")

utils.JSONResponse(w, 400, &EmailsCreateResponse{
Success: false,
Message: "Unable to update the thread",
})
return
}

}
} else {
hash := sha256.Sum256([]byte(input.Subject))

secure := "all"
if input.Kind == "raw" {
secure = "none"
}

thread := &models.Thread{
Resource: models.MakeResource(account.ID, "Encrypted thread"),
Emails: []string{resource.ID},
Labels: []string{label.ID},
Members: append(append(input.To, input.CC...), input.BCC...),
IsRead: true,
SubjectHash: hex.EncodeToString(hash[:]),
Secure: secure,
}

err := env.Threads.Insert(thread)
Expand Down