-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove duplicate in content type from bogus raw emails #1
base: master
Are you sure you want to change the base?
Conversation
|
||
var cleaned string | ||
for k := range m { | ||
cleaned += k + ";" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a space after the ;
?
Also, you can probably just return strings.Join(m, "; ")
as that is both cleaner and faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I got ahead of myself, it is a map not a slice/array. I guess you could use a bytes.Buffer
, though it won't really matter for a small number of entries.
// removeDuplicate removes duplicate from bogus content type preventing parsing of email | ||
func removeDuplicate(s string) string { | ||
m := make(map[string]bool) | ||
parts := strings.Split(s, ";") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to re-lookup content types, but isn't the very first entry a special case?
Golang map keys are random, so that image/png
entry might get put at the back of the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, I'm reading this in the RFC 2046
In general, the top-level media type is used to declare the general
type of data, while the subtype specifies a specific format for that
type of data.
Not sure if "In General" means "required" though? I can have the first attribute saved, and remove duplicate than returning first attr + the cleaned up ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds good, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just keep them all in order with a slice beside the map...
I got and error when a content type contained a duplicate example:
"image/png; x-unix-mode=0644; name=image001.png; name=image001.png"
Go's
mime.ParseMediaType
returns an error if a duplicate like this is found causing the email parsing to stop, but this is only a bogus glitches that I think only some mail client would introduce.I've added a
removeDuplicate
function that is call when the error:mime: duplicate parameter name
is returned bymime.ParseMediaType
.It's basically simply removing duplicate and retry the function.