Skip to content

Commit

Permalink
Base64 encoded email body is not decoded #86
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz committed Feb 20, 2019
1 parent 5c5b22d commit 33f1234
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cmd/mailslurper/controllers/ServiceController.go
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"strconv"
"time"

"strings"
"github.com/labstack/echo"
"github.com/mailslurper/mailslurper/pkg/auth/auth"
"github.com/mailslurper/mailslurper/pkg/auth/authfactory"
Expand Down Expand Up @@ -78,6 +78,8 @@ func (c *ServiceController) GetMail(ctx echo.Context) error {
var mailID string
var result *mailslurper.MailItem
var err error
var mailBody string
var convertSucess bool

context := contexts.GetAdminContext(ctx)

Expand All @@ -90,6 +92,11 @@ func (c *ServiceController) GetMail(ctx echo.Context) error {
c.Logger.Errorf("Problem getting mail item %s - %s", mailID, err.Error())
return context.String(http.StatusInternalServerError, "Problem getting mail item")
}
if mailBody, convertSucess = c.ConvertFromBase64(result.Body); convertSucess==true{
result.Body=mailBody
result.HTMLBody=mailBody
}


c.Logger.Infof("Mail item %s retrieved", mailID)
return context.JSON(http.StatusOK, result)
Expand Down Expand Up @@ -203,6 +210,8 @@ func (c *ServiceController) GetMailMessage(ctx echo.Context) error {
var mailID string
var mailItem *mailslurper.MailItem
var err error
var mailBody string
var convertSucess bool

context := contexts.GetAdminContext(ctx)

Expand All @@ -215,11 +224,25 @@ func (c *ServiceController) GetMailMessage(ctx echo.Context) error {
c.Logger.Errorf("Problem getting mail item %s in GetMailMessage - %s", mailID, err.Error())
return context.String(http.StatusInternalServerError, "Problem getting mail item")
}
if mailBody, convertSucess = c.ConvertFromBase64(mailItem.Body); convertSucess==true{
return context.HTML(http.StatusOK, mailBody)
}

c.Logger.Infof("Mail item %s retrieved", mailID)
return context.HTML(http.StatusOK, mailItem.Body)
}

func (c *ServiceController ) ConvertFromBase64(s string) (string,bool) {
var mailBody []byte
var err error

if mailBody, err = base64.StdEncoding.DecodeString(strings.Replace( s, " ", "", -1) ); err == nil {
return string(mailBody[:]),true
}
return "",false

}

/*
GetPruneOptions retrieves the set of options available to users for pruning
Expand Down

0 comments on commit 33f1234

Please sign in to comment.