fix: crashes when sending (#1454)

Drew Smirnoff created

## What?

Fixes crashes when sending. 

## Why?

Fixes #1453

Signed-off-by: drew <me@andrinoff.com>

Change summary

daemon/daemon.go | 6 ++++++
main.go          | 5 +++++
2 files changed, 11 insertions(+)

Detailed changes

daemon/daemon.go 🔗

@@ -544,6 +544,12 @@ func (d *Daemon) processOutbox(ctx context.Context) {
 }
 
 func (d *Daemon) sendOutboxEntry(entry *OutboxEntry) {
+	defer func() {
+		if r := recover(); r != nil {
+			log.Printf("daemon: panic sending outbox entry %s: %v", entry.ID, r)
+		}
+	}()
+
 	acct := d.getAccount(entry.Params.AccountID)
 	if acct == nil {
 		log.Printf("daemon: outbox send failed, no account for %s", entry.Params.AccountID)

main.go 🔗

@@ -1725,6 +1725,11 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { //nolint:gocyclo
 			account = m.config.GetFirstAccount()
 		}
 
+		// Ensure the service is initialized even when composing without visiting inbox.
+		if m.service == nil && m.config != nil {
+			m.service = daemonclient.NewService(m.config)
+		}
+
 		statusText := "Sending email..."
 		if msg.SignPGP && account != nil && account.PGPKeySource == "yubikey" {
 			statusText = "Touch your YubiKey to sign..."