├── .gitignore ├── Dockerfile.dev ├── go.mod ├── Dockerfile ├── helper.go ├── vars.go ├── README.md ├── message.go ├── main.go ├── go.sum └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | .DS_Store 3 | 4 | vendor 5 | 6 | # go executable built file 7 | smtp2http -------------------------------------------------------------------------------- /Dockerfile.dev: -------------------------------------------------------------------------------- 1 | FROM golang:1.14.4-alpine 2 | 3 | WORKDIR /go/src/build 4 | COPY . . 5 | ENV CGO_ENABLED=0 6 | RUN GOOS=linux GOARCH=arm64 go build -mod vendor -a -o smtp2http . 7 | 8 | ENTRYPOINT ["/go/src/build/smtp2http"] -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/alash3al/smtp2http 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/alash3al/go-smtpsrv v0.0.0-20220704173150-cdaad3f3f582 // indirect 7 | github.com/go-resty/resty/v2 v2.3.0 8 | github.com/miekg/dns v1.1.50 // indirect 9 | golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect 10 | ) 11 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.14.4 as builder 2 | RUN git clone https://github.com/alash3al/smtp2http /go/src/build 3 | WORKDIR /go/src/build 4 | RUN go mod vendor 5 | ENV CGO_ENABLED=0 6 | RUN GOOS=linux go build -mod vendor -a -o smtp2http . 7 | 8 | FROM alpine:latest 9 | WORKDIR /root/ 10 | COPY --from=builder /go/src/build/smtp2http /usr/bin/smtp2http 11 | ENTRYPOINT ["smtp2http"] 12 | -------------------------------------------------------------------------------- /helper.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/mail" 5 | ) 6 | 7 | func extractEmails(addr []*mail.Address, _ ...error) []string { 8 | ret := []string{} 9 | 10 | for _, e := range addr { 11 | ret = append(ret, e.Address) 12 | } 13 | 14 | return ret 15 | } 16 | 17 | func transformStdAddressToEmailAddress(addr []*mail.Address) []*EmailAddress { 18 | ret := []*EmailAddress{} 19 | 20 | for _, e := range addr { 21 | ret = append(ret, &EmailAddress{ 22 | Address: e.Address, 23 | Name: e.Name, 24 | }) 25 | } 26 | 27 | return ret 28 | } 29 | 30 | // func smtpsrvMesssage2EmailMessage(msg *smtpsrv.Context) 31 | -------------------------------------------------------------------------------- /vars.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "flag" 4 | 5 | var ( 6 | flagServerName = flag.String("name", "smtp2http", "the server name") 7 | flagListenAddr = flag.String("listen", ":smtp", "the smtp address to listen on") 8 | flagWebhook = flag.String("webhook", "http://localhost:8080/my/webhook", "the webhook to send the data to") 9 | flagMaxMessageSize = flag.Int64("msglimit", 1024*1024*2, "maximum incoming message size") 10 | flagReadTimeout = flag.Int("timeout.read", 5, "the read timeout in seconds") 11 | flagWriteTimeout = flag.Int("timeout.write", 5, "the write timeout in seconds") 12 | flagAuthUSER = flag.String("user", "", "user for smtp client") 13 | flagAuthPASS = flag.String("pass", "", "pass for smtp client") 14 | flagDomain = flag.String("domain", "", "domain for recieving mails") 15 | ) 16 | 17 | func init() { 18 | flag.Parse() 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SMTP2HTTP (email-to-web) 2 | ======================== 3 | smtp2http is a simple smtp server that resends the incoming email to the configured web endpoint (webhook) as a basic http post request. 4 | 5 | Dev 6 | === 7 | - `go mod vendor` 8 | - `go build` 9 | 10 | Dev with Docker 11 | ============== 12 | Locally : 13 | - `go mod vendor` 14 | - `docker build -f Dockerfile.dev -t smtp2http-dev .` 15 | - `docker run -p 25:25 smtp2http-dev --timeout.read=50 --timeout.write=50 --webhook=http://some.hook/api` 16 | 17 | Or build it as it comes from the repo : 18 | - `docker build -t smtp2http .` 19 | - `docker run -p 25:25 smtp2http --timeout.read=50 --timeout.write=50 --webhook=http://some.hook/api` 20 | 21 | The `timeout` options are of course optional but make it easier to test in local with `telnet localhost 25` 22 | Here is a telnet example payload : 23 | ``` 24 | HELO zeus 25 | # smtp answer 26 | 27 | MAIL FROM: 28 | # smtp answer 29 | 30 | RCPT TO: 31 | # smtp answer 32 | 33 | DATA 34 | your mail content 35 | . 36 | 37 | ``` 38 | 39 | Docker (production) 40 | ===== 41 | **Docker images arn't available online for now** 42 | **See "Dev with Docker" above** 43 | - `docker run -p 25:25 smtp2http --webhook=http://some.hook/api` 44 | 45 | Native usage 46 | ===== 47 | `smtp2http --listen=:25 --webhook=http://localhost:8080/api/smtp-hook` 48 | `smtp2http --help` 49 | 50 | Contribution 51 | ============ 52 | Original repo from @alash3al 53 | Thanks to @aranajuan 54 | 55 | 56 | -------------------------------------------------------------------------------- /message.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // EmailAddress ... 4 | type EmailAddress struct { 5 | Name string `json:"name,omitempty"` 6 | Address string `json:"address,omitempty"` 7 | } 8 | 9 | // EmailAttachment ... 10 | type EmailAttachment struct { 11 | Filename string `json:"filename"` 12 | ContentType string `json:"content_type"` 13 | Data string `json:"data"` 14 | } 15 | 16 | // EmailEmbeddedFile ... 17 | type EmailEmbeddedFile struct { 18 | CID string `json:"cid"` 19 | ContentType string `json:"content_type"` 20 | Data string `json:"data"` 21 | } 22 | 23 | // EmailMessage ... 24 | type EmailMessage struct { 25 | References []string `json:"references,omitempty"` 26 | SPFResult string `json:"spf,omitempty"` 27 | 28 | ID string `json:"id,omitempty"` 29 | Date string `json:"date,omitempty"` 30 | Subject string `json:"subject,omitempty"` 31 | 32 | ResentDate string `json:"resent_date,omitempty"` 33 | ResentID string `json:"resent_id,omitempty"` 34 | 35 | Body struct { 36 | Text string `json:"text,omitempty"` 37 | HTML string `json:"html,omitempty"` 38 | } `json:"body"` 39 | 40 | Addresses struct { 41 | From *EmailAddress `json:"from"` 42 | To *EmailAddress `json:"to"` 43 | ReplyTo []*EmailAddress `json:"reply_to,omitempty"` 44 | Cc []*EmailAddress `json:"cc,omitempty"` 45 | Bcc []*EmailAddress `json:"bcc,omitempty"` 46 | InReplyTo []string `json:"in_reply_to,omitempty"` 47 | 48 | ResentFrom *EmailAddress `json:"resent_from,omitempty"` 49 | ResentTo []*EmailAddress `json:"resent_to,omitempty"` 50 | ResentCc []*EmailAddress `json:"resent_cc,omitempty"` 51 | ResentBcc []*EmailAddress `json:"resent_bcc,omitempty"` 52 | } `json:"addresses"` 53 | 54 | Attachments []*EmailAttachment `json:"attachments,omitempty"` 55 | EmbeddedFiles []*EmailEmbeddedFile `json:"embedded_files,omitempty"` 56 | } 57 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/base64" 5 | "errors" 6 | "fmt" 7 | "io/ioutil" 8 | "log" 9 | "net/mail" 10 | "strings" 11 | "time" 12 | 13 | "github.com/alash3al/go-smtpsrv" 14 | "github.com/go-resty/resty/v2" 15 | ) 16 | 17 | func main() { 18 | cfg := smtpsrv.ServerConfig{ 19 | ReadTimeout: time.Duration(*flagReadTimeout) * time.Second, 20 | WriteTimeout: time.Duration(*flagWriteTimeout) * time.Second, 21 | ListenAddr: *flagListenAddr, 22 | MaxMessageBytes: int(*flagMaxMessageSize), 23 | BannerDomain: *flagServerName, 24 | Handler: smtpsrv.HandlerFunc(func(c *smtpsrv.Context) error { 25 | msg, err := c.Parse() 26 | if err != nil { 27 | return errors.New("Cannot read your message: " + err.Error()) 28 | } 29 | 30 | spfResult, _, _ := c.SPF() 31 | 32 | jsonData := EmailMessage{ 33 | ID: msg.MessageID, 34 | Date: msg.Date.String(), 35 | References: msg.References, 36 | SPFResult: spfResult.String(), 37 | ResentDate: msg.ResentDate.String(), 38 | ResentID: msg.ResentMessageID, 39 | Subject: msg.Subject, 40 | Attachments: []*EmailAttachment{}, 41 | EmbeddedFiles: []*EmailEmbeddedFile{}, 42 | } 43 | 44 | jsonData.Body.HTML = string(msg.HTMLBody) 45 | jsonData.Body.Text = string(msg.TextBody) 46 | 47 | jsonData.Addresses.From = transformStdAddressToEmailAddress([]*mail.Address{c.From()})[0] 48 | jsonData.Addresses.To = transformStdAddressToEmailAddress([]*mail.Address{c.To()})[0] 49 | 50 | toSplited := strings.Split(jsonData.Addresses.To.Address, "@") 51 | if len(*flagDomain) > 0 && (len(toSplited) < 2 || toSplited[1] != *flagDomain) { 52 | log.Println("domain not allowed") 53 | log.Println(*flagDomain) 54 | return errors.New("Unauthorized TO domain") 55 | } 56 | 57 | jsonData.Addresses.Cc = transformStdAddressToEmailAddress(msg.Cc) 58 | jsonData.Addresses.Bcc = transformStdAddressToEmailAddress(msg.Bcc) 59 | jsonData.Addresses.ReplyTo = transformStdAddressToEmailAddress(msg.ReplyTo) 60 | jsonData.Addresses.InReplyTo = msg.InReplyTo 61 | 62 | if resentFrom := transformStdAddressToEmailAddress(msg.ResentFrom); len(resentFrom) > 0 { 63 | jsonData.Addresses.ResentFrom = resentFrom[0] 64 | } 65 | 66 | jsonData.Addresses.ResentTo = transformStdAddressToEmailAddress(msg.ResentTo) 67 | jsonData.Addresses.ResentCc = transformStdAddressToEmailAddress(msg.ResentCc) 68 | jsonData.Addresses.ResentBcc = transformStdAddressToEmailAddress(msg.ResentBcc) 69 | 70 | for _, a := range msg.Attachments { 71 | data, _ := ioutil.ReadAll(a.Data) 72 | jsonData.Attachments = append(jsonData.Attachments, &EmailAttachment{ 73 | Filename: a.Filename, 74 | ContentType: a.ContentType, 75 | Data: base64.StdEncoding.EncodeToString(data), 76 | }) 77 | } 78 | 79 | for _, a := range msg.EmbeddedFiles { 80 | data, _ := ioutil.ReadAll(a.Data) 81 | jsonData.EmbeddedFiles = append(jsonData.EmbeddedFiles, &EmailEmbeddedFile{ 82 | CID: a.CID, 83 | ContentType: a.ContentType, 84 | Data: base64.StdEncoding.EncodeToString(data), 85 | }) 86 | } 87 | 88 | resp, err := resty.New().R().SetHeader("Content-Type", "application/json").SetBody(jsonData).Post(*flagWebhook) 89 | if err != nil { 90 | log.Println(err) 91 | return errors.New("E1: Cannot accept your message due to internal error, please report that to our engineers") 92 | } else if resp.StatusCode() != 200 { 93 | log.Println(resp.Status()) 94 | return errors.New("E2: Cannot accept your message due to internal error, please report that to our engineers") 95 | } 96 | 97 | return nil 98 | }), 99 | } 100 | 101 | fmt.Println(smtpsrv.ListenAndServe(&cfg)) 102 | } 103 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/alash3al/go-smtpsrv v0.0.0-20220704173150-cdaad3f3f582 h1:eF7ZF/hA+HCoWLZl9a2eia0634gSQ44JljrKGFsCN7Y= 2 | github.com/alash3al/go-smtpsrv v0.0.0-20220704173150-cdaad3f3f582/go.mod h1:koTAnESO0en2jpEeCOnjZCxsPcIzWNWaVjBdDPmug9w= 3 | github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ= 4 | github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= 5 | github.com/emersion/go-smtp v0.13.0 h1:aC3Kc21TdfvXnuJXCQXuhnDXUldhc12qME/S7Y3Y94g= 6 | github.com/emersion/go-smtp v0.13.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ= 7 | github.com/go-resty/resty/v2 v2.3.0 h1:JOOeAvjSlapTT92p8xiS19Zxev1neGikoHsXJeOq8So= 8 | github.com/go-resty/resty/v2 v2.3.0/go.mod h1:UpN9CgLZNsv4e9XG50UU8xdI0F43UQ4HmxLBDwaroHU= 9 | github.com/miekg/dns v1.1.29 h1:xHBEhR+t5RzcFJjBLJlax2daXOrTYtr9z4WdKEfWFzg= 10 | github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= 11 | github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA= 12 | github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= 13 | github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 14 | github.com/zaccone/spf v0.0.0-20170817004109-76747b8658d9 h1:NugUf62Z6Yzn//u/MT+cuaFX1AFzfuIR9QVywUQX18E= 15 | github.com/zaccone/spf v0.0.0-20170817004109-76747b8658d9/go.mod h1:AL91TJsHKIaWR16S1IaxTSZfBRMr3/dOdiN1OZ1m9RM= 16 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 17 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 18 | golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM= 19 | golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 20 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 21 | golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= 22 | golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 23 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 24 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 25 | golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 26 | golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 27 | golang.org/x/net v0.0.0-20200602114024-627f9648deb9 h1:pNX+40auqi2JqRfOP1akLGtYcn15TUbkhwuCO3foqqM= 28 | golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 29 | golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= 30 | golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 h1:4CSI6oo7cOjJKajidEljs9h+uP0rRZBPPPhcCbj5mw8= 31 | golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 32 | golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= 33 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 34 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 35 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 36 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 37 | golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 38 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 39 | golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y= 40 | golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 41 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 42 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 43 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 44 | golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 45 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= 46 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 47 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 48 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 49 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 50 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 51 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= 52 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 53 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 54 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 55 | golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 56 | golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 h1:BonxutuHCTL0rBDnZlKjpGIQFTjyUVTexFOdWkB6Fg0= 57 | golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= 58 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 59 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 60 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 61 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------