summaryrefslogtreecommitdiffstats
path: root/utils/inbucket.go
diff options
context:
space:
mode:
authorJonathan Fritz <jonathan.fritz@mattermost.com>2018-02-13 08:39:56 -0500
committerJonathan Fritz <jonathan.fritz@mattermost.com>2018-02-13 08:39:56 -0500
commit18fa32567b56584c6e24da2ae68814d5bf8ece6f (patch)
tree311ab6a3918ba64ac665286f15950b32dc1b1dba /utils/inbucket.go
parent7b2861de3a09cf00d00b0872cc537d54302c4bfa (diff)
parent8b79f5d49cb8d4877e136a76e515edef41ef6f28 (diff)
downloadchat-18fa32567b56584c6e24da2ae68814d5bf8ece6f.tar.gz
chat-18fa32567b56584c6e24da2ae68814d5bf8ece6f.tar.bz2
chat-18fa32567b56584c6e24da2ae68814d5bf8ece6f.zip
Merge branch 'release-4.7' into XYZ-110
Diffstat (limited to 'utils/inbucket.go')
-rw-r--r--utils/inbucket.go52
1 files changed, 6 insertions, 46 deletions
diff --git a/utils/inbucket.go b/utils/inbucket.go
index 5c40d5757..46011989b 100644
--- a/utils/inbucket.go
+++ b/utils/inbucket.go
@@ -4,7 +4,6 @@
package utils
import (
- "bytes"
"encoding/json"
"fmt"
"io"
@@ -38,12 +37,6 @@ type JSONMessageInbucket struct {
Text string
HTML string `json:"Html"`
}
- Attachments []struct {
- Filename string
- ContentType string `json:"content-type"`
- DownloadLink string `json:"download-link"`
- Bytes []byte `json:"-"`
- }
}
func ParseEmail(email string) string {
@@ -96,54 +89,21 @@ func GetMessageFromMailbox(email, id string) (results JSONMessageInbucket, err e
var record JSONMessageInbucket
url := fmt.Sprintf("%s%s%s/%s", getInbucketHost(), INBUCKET_API, parsedEmail, id)
- emailResponse, err := get(url)
- if err != nil {
- return record, err
- }
- defer emailResponse.Body.Close()
-
- err = json.NewDecoder(emailResponse.Body).Decode(&record)
-
- // download attachments
- if record.Attachments != nil && len(record.Attachments) > 0 {
- for i := range record.Attachments {
- if bytes, err := downloadAttachment(record.Attachments[i].DownloadLink); err != nil {
- return record, err
- } else {
- record.Attachments[i].Bytes = make([]byte, len(bytes))
- copy(record.Attachments[i].Bytes, bytes)
- }
- }
- }
-
- return record, err
-}
-
-func downloadAttachment(url string) ([]byte, error) {
- attachmentResponse, err := get(url)
- if err != nil {
- return nil, err
- }
- defer attachmentResponse.Body.Close()
-
- buf := new(bytes.Buffer)
- io.Copy(buf, attachmentResponse.Body)
- return buf.Bytes(), nil
-}
-
-func get(url string) (*http.Response, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
- return nil, err
+ return record, err
}
client := &http.Client{}
+
resp, err := client.Do(req)
if err != nil {
- return nil, err
+ return record, err
}
+ defer resp.Body.Close()
- return resp, nil
+ err = json.NewDecoder(resp.Body).Decode(&record)
+ return record, err
}
func DeleteMailBox(email string) (err error) {