mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 07:36:44 +00:00
refactor: remove dead code
This commit is contained in:
@ -45,6 +45,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,3 +97,13 @@ func selectDecoderFromParams(params map[string]string) *encoding.Decoder {
|
|||||||
|
|
||||||
return decoder
|
return decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Part) is7BitClean() bool {
|
||||||
|
for _, b := range p.Body {
|
||||||
|
if b > 1<<7 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@ -25,28 +25,16 @@ import (
|
|||||||
|
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
root *Part
|
root *Part
|
||||||
cond []Condition
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Condition func(p *Part) bool
|
|
||||||
|
|
||||||
func newWriter(root *Part) *Writer {
|
func newWriter(root *Part) *Writer {
|
||||||
return &Writer{
|
return &Writer{
|
||||||
root: root,
|
root: root,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithCondition allows setting a condition when parts should be written.
|
|
||||||
// Parts are passed to each condition set and if any condition returns false,
|
|
||||||
// the part is not written.
|
|
||||||
// This initially seemed like a good idea but is now kinda useless.
|
|
||||||
func (w *Writer) WithCondition(cond Condition) *Writer {
|
|
||||||
w.cond = append(w.cond, cond)
|
|
||||||
return w
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) Write(ww io.Writer) error {
|
func (w *Writer) Write(ww io.Writer) error {
|
||||||
if w.shouldFilter(w.root) {
|
if !w.root.is7BitClean() {
|
||||||
w.root.Header.Add("Content-Transfer-Encoding", "base64")
|
w.root.Header.Add("Content-Transfer-Encoding", "base64")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,32 +50,6 @@ func (w *Writer) Write(ww io.Writer) error {
|
|||||||
return msgWriter.Close()
|
return msgWriter.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) shouldWrite(p *Part) bool {
|
|
||||||
for _, cond := range w.cond {
|
|
||||||
if !cond(p) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) shouldFilter(p *Part) bool {
|
|
||||||
encoding := p.Header.Get("Content-Transfer-Encoding")
|
|
||||||
|
|
||||||
if encoding != "" && encoding == "quoted-printable" || encoding == "base64" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, b := range p.Body {
|
|
||||||
if b > 1<<7 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Writer) write(writer *message.Writer, p *Part) error {
|
func (w *Writer) write(writer *message.Writer, p *Part) error {
|
||||||
if len(p.children) > 0 {
|
if len(p.children) > 0 {
|
||||||
for _, child := range p.children {
|
for _, child := range p.children {
|
||||||
@ -105,11 +67,7 @@ func (w *Writer) write(writer *message.Writer, p *Part) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) writeAsChild(writer *message.Writer, p *Part) error {
|
func (w *Writer) writeAsChild(writer *message.Writer, p *Part) error {
|
||||||
if !w.shouldWrite(p) {
|
if !p.is7BitClean() {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if w.shouldFilter(p) {
|
|
||||||
p.Header.Add("Content-Transfer-Encoding", "base64")
|
p.Header.Add("Content-Transfer-Encoding", "base64")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,26 +36,6 @@ func TestParserWrite(t *testing.T) {
|
|||||||
assert.Equal(t, s("text_html_octet_attachment.eml"), crlf(buf.String()))
|
assert.Equal(t, s("text_html_octet_attachment.eml"), crlf(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParserWriteNoAttachments(t *testing.T) {
|
|
||||||
p := newTestParser(t, "text_html_octet_attachment.eml")
|
|
||||||
|
|
||||||
w := p.
|
|
||||||
NewWriter().
|
|
||||||
WithCondition(func(p *Part) bool {
|
|
||||||
// We don't write if the content disposition says it's an attachment.
|
|
||||||
if disp, _, err := p.Header.ContentDisposition(); err == nil && disp == "attachment" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
|
|
||||||
assert.NoError(t, w.Write(buf))
|
|
||||||
assert.Equal(t, s("text_html.eml"), crlf(buf.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func crlf(s string) string {
|
func crlf(s string) string {
|
||||||
return strings.ReplaceAll(s, "\r\n", "\n")
|
return strings.ReplaceAll(s, "\r\n", "\n")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user