forked from Silverfish/proton-bridge
Other: add straightforward linters
This commit is contained in:
@ -51,9 +51,8 @@ func WriteAttachmentBody(w io.Writer, kr *crypto.KeyRing, m *pmapi.Message, att
|
||||
var dr io.Reader
|
||||
dr, err = att.Decrypt(r, kr)
|
||||
if err == openpgperrors.ErrKeyIncorrect {
|
||||
// Do not fail if attachment is encrypted with a different key.
|
||||
err = nil //nolint[wastedassing] Do not fail if attachment is encrypted with a different key.
|
||||
dr = r
|
||||
err = nil
|
||||
att.Name += ".gpg"
|
||||
att.MIMEType = "application/pgp-encrypted" //nolint
|
||||
} else if err != nil && err != openpgperrors.ErrSignatureExpired {
|
||||
|
||||
@ -48,7 +48,7 @@ func NewBuilder(client pmapi.Client, message *pmapi.Message) *Builder {
|
||||
return &Builder{cl: client, msg: message, EncryptedToHTML: true, successfullyDecrypted: false}
|
||||
}
|
||||
|
||||
// fetchMessage will update original PM message if successful
|
||||
// fetchMessage will update original PM message if successful.
|
||||
func (bld *Builder) fetchMessage() (err error) {
|
||||
if bld.msg.Body != "" {
|
||||
return nil
|
||||
@ -211,11 +211,11 @@ func (bld *Builder) BuildMessage() (structure *BodyStructure, message []byte, er
|
||||
return structure, message, err
|
||||
}
|
||||
|
||||
// SuccessfullyDecrypted is true when message was fetched and decrypted successfully
|
||||
// SuccessfullyDecrypted is true when message was fetched and decrypted successfully.
|
||||
func (bld *Builder) SuccessfullyDecrypted() bool { return bld.successfullyDecrypted }
|
||||
|
||||
// WriteBody decrypts PM message and writes main body section. The external PGP
|
||||
// message is written as is (including attachments)
|
||||
// message is written as is (including attachments).
|
||||
func (bld *Builder) WriteBody(w io.Writer) error {
|
||||
kr, err := bld.cl.KeyRingForAddressID(bld.msg.AddressID)
|
||||
if err != nil {
|
||||
@ -238,7 +238,7 @@ func (bld *Builder) WriteBody(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// WriteAttachmentBody decrypts and writes the attachments
|
||||
// WriteAttachmentBody decrypts and writes the attachments.
|
||||
func (bld *Builder) WriteAttachmentBody(w io.Writer, att *pmapi.Attachment, attReader io.Reader) (err error) {
|
||||
kr, err := bld.cl.KeyRingForAddressID(bld.msg.AddressID)
|
||||
if err != nil {
|
||||
@ -248,9 +248,8 @@ func (bld *Builder) WriteAttachmentBody(w io.Writer, att *pmapi.Attachment, attR
|
||||
var dr io.Reader
|
||||
dr, err = att.Decrypt(attReader, kr)
|
||||
if err == openpgperrors.ErrKeyIncorrect {
|
||||
// Do not fail if attachment is encrypted with a different key
|
||||
err = nil //nolint[wastedasign] Do not fail if attachment is encrypted with a different key
|
||||
dr = attReader
|
||||
err = nil
|
||||
att.Name += ".gpg"
|
||||
att.MIMEType = "application/pgp-encrypted"
|
||||
} else if err != nil && err != openpgperrors.ErrSignatureExpired {
|
||||
|
||||
@ -38,7 +38,7 @@ type SectionInfo struct {
|
||||
reader io.Reader
|
||||
}
|
||||
|
||||
// Read and count
|
||||
// Read and count.
|
||||
func (si *SectionInfo) Read(p []byte) (n int, err error) {
|
||||
n, err = si.reader.Read(p)
|
||||
si.Size += n
|
||||
@ -237,11 +237,11 @@ func (bs *BodyStructure) parseAllChildSections(r io.Reader, currentPath []int, s
|
||||
}
|
||||
|
||||
// Clear all buffers.
|
||||
bodyReader = nil
|
||||
bodyReader = nil //nolint[wastedassign] just to be sure we clear garbage collector
|
||||
bodyInfo.reader = nil
|
||||
tp.R = nil
|
||||
tp = nil
|
||||
bufInfo = nil // nolint
|
||||
tp = nil //nolint[wastedassign] just to be sure we clear garbage collector
|
||||
bufInfo = nil //nolint[ineffassign] just to be sure we clear garbage collector
|
||||
info.reader = nil
|
||||
|
||||
// Store boundaries.
|
||||
@ -305,6 +305,11 @@ func stringPathFromInts(ints []int) (ret string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (bs *BodyStructure) hasInfo(sectionPath []int) bool {
|
||||
_, err := bs.getInfo(sectionPath)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (bs *BodyStructure) getInfo(sectionPath []int) (sectionInfo *SectionInfo, err error) {
|
||||
path := stringPathFromInts(sectionPath)
|
||||
sectionInfo, ok := (*bs)[path]
|
||||
@ -404,7 +409,7 @@ func (bs *BodyStructure) IMAPBodyStructure(currentPart []int) (imapBS *imap.Body
|
||||
|
||||
nextPart := append(currentPart, 1)
|
||||
for {
|
||||
if _, err := bs.getInfo(nextPart); err != nil {
|
||||
if !bs.hasInfo(nextPart) {
|
||||
break
|
||||
}
|
||||
var subStruct *imap.BodyStructure
|
||||
|
||||
Reference in New Issue
Block a user