Convert panics from message parser to error

This commit is contained in:
Michal Horejsek
2020-08-31 15:57:45 +02:00
parent 61867fbde7
commit 1d2e584799
7 changed files with 16 additions and 7 deletions

View File

@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Code generated by ./credits.sh at Fri Aug 21 10:29:43 CEST 2020. DO NOT EDIT.
// Code generated by ./credits.sh at Mon Aug 31 15:08:14 CEST 2020. DO NOT EDIT.
package bridge

View File

@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Code generated by ./release-notes.sh at 'Thu Aug 20 14:25:06 CEST 2020'. DO NOT EDIT.
// Code generated by ./release-notes.sh at 'Mon Aug 31 15:08:14 CEST 2020'. DO NOT EDIT.
package bridge

View File

@ -185,7 +185,9 @@ func (f *frontendCLI) setTransferRules(t *transfer.Transfer) bool {
func (f *frontendCLI) printTransferProgress(progress *transfer.Progress) {
failed, imported, exported, added, total := progress.GetCounts()
f.Println(fmt.Sprintf("Progress update: %d (%d / %d) / %d, failed: %d", imported, exported, added, total, failed))
if total != 0 {
f.Println(fmt.Sprintf("Progress update: %d (%d / %d) / %d, failed: %d", imported, exported, added, total, failed))
}
if progress.IsPaused() {
f.Printf("Transfer is paused bacause %s", progress.PauseReason())

View File

@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Code generated by ./credits.sh at Fri Aug 21 10:29:44 CEST 2020. DO NOT EDIT.
// Code generated by ./credits.sh at Mon Aug 31 15:08:14 CEST 2020. DO NOT EDIT.
package importexport

View File

@ -15,7 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
// Code generated by ./release-notes.sh at 'Fri Aug 21 14:17:14 CEST 2020'. DO NOT EDIT.
// Code generated by ./release-notes.sh at 'Mon Aug 31 15:08:14 CEST 2020'. DO NOT EDIT.
package importexport

View File

@ -206,7 +206,14 @@ func (p *PMAPIProvider) generateImportMsgReq(msg Message, globalMailbox *Mailbox
}, nil
}
func (p *PMAPIProvider) parseMessage(msg Message) (*pmapi.Message, []io.Reader, error) {
func (p *PMAPIProvider) parseMessage(msg Message) (m *pmapi.Message, r []io.Reader, err error) {
// Old message parser is panicking in some cases.
// Instead of crashing we try to convert to regular error.
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
}
}()
message, _, _, attachmentReaders, err := pkgMessage.Parse(bytes.NewBuffer(msg.Body), "", "")
return message, attachmentReaders, err
}