8000 Email: easier setup, folders with spaces, and cancelled loads by Thomaspeel6 · Pull Request #7 · joexk1/JoeBro · GitHub
[go: up one dir, main page]

Skip to content

Email: easier setup, folders with spaces, and cancelled loads - #7

Open
Thomaspeel6 wants to merge 3 commits into
joexk1:mainfrom
Thomaspeel6:email-simple-connect
Open

Thomaspeel6 wants to merge 3 commits into
joexk1:mainfrom
Thomaspeel6:email-simple-connect

Conversation

@Thomaspeel6
@Thomaspeel6 Thomaspeel6 commented Nov 13, 2026 •
Copy link
Copy Markdown

Three email changes found while connecting a Gmail account, one commit each. Part of the email setup proposal in #8.

1. Setup asks for address and app password only, and signs in before saving

Why: Connecting a mailbox currently means knowing your provider's IMAP and SMTP hosts and ports, and the Connect button stays disabled until all four are typed in. The backend can already work them out from the address for Gmail, iCloud, Outlook, Fastmail and Yahoo (email_account_from_login, behind /api/email/connect), but nothing called that route.

  • Form (SettingsView.swift, APIClient.swift): address and app password use /api/email/connect. The four server fields move under "Advanced: mail servers" and still go through /api/email/connect-imap. A "How to create a … app password" link appears for Gmail, iCloud, Yahoo and Fastmail addresses.
  • Sign in before saving (jb_email.py, joebro_backend.py): both connect routes try the IMAP login first and return a readable error. Before, a wrong password or host was saved as connected and only showed up later as an error in the inbox.
  • TLS mode from the port: a manual setup that doesn't state the TLS mode now infers it (143 and 587/25 use STARTTLS). Both used to default to implicit TLS, so a mailbox set up from the Mac form with SMTP port 587 (iCloud, Outlook) could not send.

2. Folders with a space in the name fail to open

Selecting any Gmail folder other than Inbox ("[Gmail]/Sent Mail", "[Gmail]/All Mail"), or any user folder with a space in its name, shows:

EXAMINE command error: BAD [b'Could not parse command']

imaplib sends mailbox names verbatim, so a name with a space reaches the server as two arguments. A small imap_mailbox() helper now sends the name as an IMAP quoted string, in the four places a folder is selected.

3. A cancelled load is shown as "Couldn't load — cancelled"

The inbox load runs in a .task keyed on folder and filter, so SwiftUI cancels it when the tab or folder changes, and the catch reported that as a failure over a working mailbox. A cancelled load is now ignored; the next one replaces it (EmailPanel.swift).

Behaviour changes to be aware of

  • Adding a mailbox now needs the mail server to be reachable, and takes a few seconds longer.
  • Existing saved mailboxes are not touched. One that was saved with port 587 and the wrong TLS mode stays that way until it is removed and added again; I haven't added a repair for those rows.
  • Bridge accounts (_bridge_types()) skip the login check, as before.

Tested

  • 9 new tests in test_email.py and test_email_folders.py, run against a local fake IMAP server. Email had none. The full backend suite passes (92 tests) on the macOS system Python.
  • Against a real Gmail account: before the folder fix only Inbox loaded; after it, Sent Mail, All Mail and user folders with spaces all return mail through /api/email/list.
  • Against the running backend: an unreachable domain returns the "Couldn't reach the mail server…" error with HTTP 400 and saves nothing.
  • Built in Xcode 26.5 on macOS 26.2.
  • Not tested: the rejected-password message against a real provider (only against the fake server), a real iCloud or Outlook account, SMTP sign-in (the check is IMAP only), and the cancelled-load race on screen (fixed by reading the code path). I checked the backend through its API rather than by clicking through the form and the Email tab.

If you'd rather review these separately, the three commits split cleanly.

…e saving

The Connect Email sheet required IMAP and SMTP hosts and ports, although the
backend can already derive them from the address for Gmail, iCloud, Outlook,
Fastmail and Yahoo (email_account_from_login, via /api/email/connect, which
nothing called). The sheet now asks for the address and an app password, uses
that route, and keeps the server fields under "Advanced: mail servers" for
other providers. A link to the provider's app-password page appears once the
address is recognised.

Both connect routes now try the IMAP login before saving and return a readable
error. Previously a wrong password or host was saved as connected and only
surfaced later as an error in the inbox.

A manual setup that does not state the TLS mode now infers it from the port
(143 and 587/25 use STARTTLS). Defaulting both to implicit TLS meant a mailbox
set up with SMTP port 587 could not send.

Adds the first email tests, run against a local fake IMAP server.
imaplib sends mailbox names verbatim, so a name containing a space reached the
server as two arguments. Every Gmail system folder except INBOX ("[Gmail]/Sent
Mail", "[Gmail]/All Mail") and any user folder with a space failed with
"EXAMINE command error: BAD Could not parse command".

Names are now sent as IMAP quoted strings wherever a folder is selected.
The inbox load runs in a .task keyed on folder and filter, so it is cancelled
when the tab is switched away or the folder changes. The catch block showed
that as "Couldn't load — cancelled", even over a working mailbox. A cancelled
load is now ignored; the next load replaces it.
@Thomaspeel6 Thomaspeel6 changed the title Email setup: ask for address and app password only, and sign in before saving Email: easier setup, folders with spaces, and cancelled loads Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0