Skip to content

fix: refactor and fix inbound email handling#388

Merged
eshanholtz merged 8 commits intomasterfrom
refactor-inbound-parse
May 12, 2020
Merged

fix: refactor and fix inbound email handling#388
eshanholtz merged 8 commits intomasterfrom
refactor-inbound-parse

Conversation

@eshanholtz
Copy link
Copy Markdown
Contributor

Fixes #383

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Apr 21, 2020
Comment thread helpers/inbound/inbound.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2020

Codecov Report

Merging #388 into master will increase coverage by 22.75%.
The diff coverage is 91.66%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #388       +/-   ##
===========================================
+ Coverage   72.47%   95.23%   +22.75%     
===========================================
  Files           3        3               
  Lines         476      399       -77     
===========================================
+ Hits          345      380       +35     
+ Misses        127       14      -113     
- Partials        4        5        +1     
Impacted Files Coverage Δ
helpers/inbound/inbound.go 89.28% <91.66%> (+78.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49500d8...49b5251. Read the comment docs.

Comment thread helpers/inbound/inbound.go Outdated
Comment thread helpers/inbound/inbound.go Outdated
Comment thread helpers/inbound/inbound.go Outdated
Comment thread helpers/inbound/inbound_test.go Outdated
@thinkingserious
Copy link
Copy Markdown
Contributor

Need to update the README. We can no longer do go run inbound.go as it returns go run: cannot run non-main package.

Copy link
Copy Markdown
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome refactor! 🥇

Comment thread helpers/inbound/inbound.go Outdated
Copy link
Copy Markdown
Contributor

@thinkingserious thinkingserious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can now delete conf.json since the Heroku deploy functionality is removed.

Not sure if this is in scope (perhaps we create a separate issue for this), but it feels like we should have at least one working "hello inbound email" email example. Something simple, like the following:

package main

import (
	"fmt"
	"log"
	"net/http"

         "github.com/sendgrid/sendgrid-go/helpers/inbound"
)

func inboundHandler(response http.ResponseWriter, request *http.Request) {
	parsedEmail := Parse(response, request)

	fmt.Print(parsedEmail.Headers["From"])

	for filename, contents := range parsedEmail.Attachments {
		// Do something with an attachment
		handleAttachment(filename, contents)
	}

	for section, body := range parsedEmail.Body {
		// Do something with the email body
		handleEmail(body)
	}
}

func main() {
	http.HandleFunc("/inbound", inboundHandler)
	if err := http.ListenAndServe(":8000", nil); err != nil {
		log.Fatalln("Error")
	}
}

Comment thread helpers/inbound/README.md Outdated
Comment thread helpers/inbound/inbound.go Outdated
Comment thread helpers/inbound/inbound_test.go Outdated
Comment thread helpers/inbound/README.md
Comment thread helpers/inbound/README.md Outdated
@childish-sambino
Copy link
Copy Markdown
Contributor

Woohoo: +195 −302

@eshanholtz eshanholtz merged commit cb42c17 into master May 12, 2020
@eshanholtz eshanholtz deleted the refactor-inbound-parse branch May 12, 2020 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: code review request requesting a community code review or review from Twilio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inbound parse handler example panics on sample raw data

3 participants