From 429438e56441447ebc64c335cf30e66604404418 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Tue, 28 Apr 2026 00:37:00 -0700 Subject: [PATCH] fix(sender): capture Write errors in SendCalendarReply iMIP body (#1128) The multipart body for an iMIP calendar reply was built with direct Write / Fprint calls whose errors were discarded. A short write or buffer error there produces a malformed reply that Google Calendar and Outlook silently reject without recording the RSVP. Capture the error from each of the eight writes/closes in the iMIP body block and return early. No behavior change on the success path. --- sender/sender.go | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/sender/sender.go b/sender/sender.go index caba62d..225b295 100644 --- a/sender/sender.go +++ b/sender/sender.go @@ -800,8 +800,12 @@ func SendCalendarReply(account *config.Account, to []string, subject, plainBody return nil, err } qp := quotedprintable.NewWriter(plainPart) - fmt.Fprint(qp, plainBody) - qp.Close() + if _, err := fmt.Fprint(qp, plainBody); err != nil { + return nil, err + } + if err := qp.Close(); err != nil { + return nil, err + } // text/calendar inline part (Outlook/Mac Mail use this) calHeader := textproto.MIMEHeader{} @@ -811,10 +815,16 @@ func SendCalendarReply(account *config.Account, to []string, subject, plainBody if err != nil { return nil, err } - calPart.Write([]byte(clib.WrapBase64(base64.StdEncoding.EncodeToString(icsData)))) + if _, err := calPart.Write([]byte(clib.WrapBase64(base64.StdEncoding.EncodeToString(icsData)))); err != nil { + return nil, err + } - altWriter.Close() - altPart.Write(altMsg.Bytes()) + if err := altWriter.Close(); err != nil { + return nil, err + } + if _, err := altPart.Write(altMsg.Bytes()); err != nil { + return nil, err + } // .ics file attachment (Gmail uses this) attachHeader := textproto.MIMEHeader{} @@ -825,10 +835,16 @@ func SendCalendarReply(account *config.Account, to []string, subject, plainBody if err != nil { return nil, err } - attachPart.Write([]byte(clib.WrapBase64(base64.StdEncoding.EncodeToString(icsData)))) + if _, err := attachPart.Write([]byte(clib.WrapBase64(base64.StdEncoding.EncodeToString(icsData)))); err != nil { + return nil, err + } - outerWriter.Close() - msg.Write(outerMsg.Bytes()) + if err := outerWriter.Close(); err != nil { + return nil, err + } + if _, err := msg.Write(outerMsg.Bytes()); err != nil { + return nil, err + } // Send via SMTP addr := fmt.Sprintf("%s:%d", smtpServer, smtpPort)