forked from tgulacsi/agostle
/
outlook.go
45 lines (35 loc) · 1.12 KB
/
outlook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2013 The Agostle Authors. All rights reserved.
// Use of this source code is governed by an Apache 2.0
// license that can be found in the LICENSE file.
package main
// Needed: /email/convert?splitted=1&errors=1&id=xxx Accept: images/gif
// /pdf/merge Accept: application/zip
import (
"io"
"net/http"
"golang.org/x/net/context"
"github.com/tgulacsi/agostle/converter"
kithttp "github.com/go-kit/kit/transport/http"
)
var outlookToEmailServer = kithttp.NewServer(
context.Background(),
outlookToEmailEP,
outlookToEmailDecode,
outlookToEmailEncode,
kithttp.ServerBefore(defaultBeforeFuncs...),
kithttp.ServerAfter(kithttp.SetContentType("mail/rfc822")),
)
func outlookToEmailDecode(r *http.Request) (interface{}, error) {
return getOneRequestFile(r)
}
func outlookToEmailEP(ctx context.Context, request interface{}) (response interface{}, err error) {
f := request.(reqFile)
defer f.Close()
return converter.NewOLEStorageReader(f)
}
func outlookToEmailEncode(w http.ResponseWriter, response interface{}) error {
res := response.(io.ReadCloser)
defer res.Close()
_, err := io.Copy(w, res)
return err
}