forked from Silverfish/proton-bridge
feat: attach public key
This commit is contained in:
@ -45,7 +45,6 @@ func Parse(r io.Reader, key, keyName string) (m *pmapi.Message, mimeBody, plainB
|
|||||||
}
|
}
|
||||||
|
|
||||||
if key != "" {
|
if key != "" {
|
||||||
// TODO: This is currently broken!
|
|
||||||
if err = attachPublicKey(p.Root(), key, keyName); err != nil {
|
if err = attachPublicKey(p.Root(), key, keyName); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,7 +48,20 @@ func (p *Part) Children() Parts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Part) AddChild(child *Part) {
|
func (p *Part) AddChild(child *Part) {
|
||||||
|
if p.isMultipartMixed() {
|
||||||
p.children = append(p.children, child)
|
p.children = append(p.children, child)
|
||||||
|
} else {
|
||||||
|
root := &Part{
|
||||||
|
Header: getContentHeaders(p.Header),
|
||||||
|
Body: p.Body,
|
||||||
|
children: p.children,
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Body = nil
|
||||||
|
p.children = Parts{root, child}
|
||||||
|
stripContentHeaders(&p.Header)
|
||||||
|
p.Header.Set("Content-Type", "multipart/mixed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Part) ConvertToUTF8() error {
|
func (p *Part) ConvertToUTF8() error {
|
||||||
@ -107,3 +120,28 @@ func (p *Part) is7BitClean() bool {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Part) isMultipartMixed() bool {
|
||||||
|
t, _, err := p.Header.ContentType()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return t == "multipart/mixed"
|
||||||
|
}
|
||||||
|
|
||||||
|
func getContentHeaders(header message.Header) message.Header {
|
||||||
|
var res message.Header
|
||||||
|
|
||||||
|
res.Set("Content-Type", header.Get("Content-Type"))
|
||||||
|
res.Set("Content-Disposition", header.Get("Content-Disposition"))
|
||||||
|
res.Set("Content-Transfer-Encoding", header.Get("Content-Transfer-Encoding"))
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
func stripContentHeaders(header *message.Header) {
|
||||||
|
header.Del("Content-Type")
|
||||||
|
header.Del("Content-Disposition")
|
||||||
|
header.Del("Content-Transfer-Encoding")
|
||||||
|
}
|
||||||
|
|||||||
@ -313,7 +313,6 @@ func TestParseTextHTMLWithImageInline(t *testing.T) {
|
|||||||
func TestParseWithAttachedPublicKey(t *testing.T) {
|
func TestParseWithAttachedPublicKey(t *testing.T) {
|
||||||
f := f("text_plain.eml")
|
f := f("text_plain.eml")
|
||||||
|
|
||||||
// BAD: Public Key is not attached unless Content-Type is specified (not required)!
|
|
||||||
m, _, plainBody, attReaders, err := Parse(f, "publickey", "publickeyname")
|
m, _, plainBody, attReaders, err := Parse(f, "publickey", "publickeyname")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -323,7 +322,6 @@ func TestParseWithAttachedPublicKey(t *testing.T) {
|
|||||||
assert.Equal(t, "body", m.Body)
|
assert.Equal(t, "body", m.Body)
|
||||||
assert.Equal(t, "body", plainBody)
|
assert.Equal(t, "body", plainBody)
|
||||||
|
|
||||||
// HELP: Should public key be available as an attachment? In previous parser it wasn't...
|
|
||||||
require.Len(t, attReaders, 1)
|
require.Len(t, attReaders, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user