Skip to content

Commit

Permalink
SMTP: Adding endpoint for accessing RawMessageData (incl. link in GUI)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Hinderberger committed Jul 1, 2024
1 parent fcf20b0 commit e02654c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/smtp/gui.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<pre id="msgmeta"></pre>
</p>

<p>
<strong>Raw Message:</strong><br>
<a id="rawlink" href="javascript:void(0)" target="_blank">Download</a>
</p>

<p>
<strong>Body:</strong><br>
<a id="bodylink" href="javascript:void(0)" target="_blank">Show</a>
Expand All @@ -70,6 +75,7 @@
const msgmeta = document.getElementById("msgmeta")
const multimeta = document.getElementById("multimeta")
const partlist = document.getElementById("partlist")
const rawlink = document.getElementById("rawlink")

let n_received = 0
let index = {"count": 0, "messages": []}
Expand Down Expand Up @@ -103,6 +109,7 @@
msgmeta.textContent = JSON.stringify(metadata, null, 2)

bodylink.href = `${prefix}/${idx}/body`
rawlink.href = `${prefix}/${idx}/raw`

partlist.innerHTML=""

Expand Down
14 changes: 14 additions & 0 deletions internal/smtp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (h *smtpHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case "multipart":
h.handleMultipartIndex(w, r, idx)
return
case "raw":
h.handleRawMessageData(w, r, idx)
return
}
case 3, 4:
if pathParts[1] == "multipart" {
Expand Down Expand Up @@ -247,6 +250,17 @@ func (h *smtpHTTPHandler) handleMultipartBody(
w.Write(part.Body())
}

func (h *smtpHTTPHandler) handleRawMessageData(w http.ResponseWriter, r *http.Request, idx int) {
msg := h.retrieveMessage(w, idx)
if msg == nil {
return
}

w.Header().Set("Content-Type", "message/rfc822")

w.Write(msg.RawMessageData())
}

// retrieveMessage tries to retrieve the ReceivedMessage with the given index.
// If found, returns the message. If not found, responds with Status 404
// and returns nil.
Expand Down

0 comments on commit e02654c

Please sign in to comment.