Replace nsISocketTransportService with TCPSocket for TB 115+#1145
Replace nsISocketTransportService with TCPSocket for TB 115+#1145heeen wants to merge 7 commits intothsmi:masterfrom
Conversation
Replace the broken nsISocketTransportService approach with a new experiment API wrapping Thunderbird's internal TCPSocket component. This is the same TCPSocket that TB uses for its own SMTP/IMAP implementations, avoiding the StartTLS threading issue that broke the extension in TB 115+. The API separates socket creation from connection to prevent races between the WebExtension thread and the network thread -- listeners are registered on a proxy object before TCPSocket is constructed. Based on work from the 893-does-not-work-with-tb-115 branch with fixes: removed dead Services.jsm fallback, fixed shutdownSockets() method call, aligned schema with implementation (getSSL, onError parameters).
The new TCPSocket experiment API is fully async (cross-thread WebExtension calls). Propagate async through the abstract base classes and all callers to prepare for the socket API switch.
The TCPSocket API expects an integer port. Parse the port from the URL string into a number at construction time and validate it, rather than lazily stringifying the default port on access.
Follow-up to the SieveUrl integer port change -- update test assertions from string "4190"/"1234" to integer 4190/1234.
Replace the broken browser.sieve.socket.* API (which used nsISocketTransportService directly) with the new browser.tcpSocket.* experiment API (which uses Thunderbird's internal TCPSocket component). Key changes: - create() no longer takes host/port; connect() takes them separately - startTLS() replaced by upgradeToSecure() - isAlive() now checks getReadyState() for "open" - send() replaced by sendBytes() with ArrayBuffer - Error handler correctly dispatches on type string parameter - Minimum Thunderbird version bumped to 115.0 Fixes thsmi#893
The handlers use await for isConnected() but were not declared as async functions, causing a SyntaxError at runtime.
When the extension reloads, shutdownSockets() destroys all sockets before ExtensionCommon's EventManager fires removeListener callbacks. Guard each unregister callback with hasSocket() to avoid "Unknown socket" errors during shutdown.
|
@heeen what is the intention behind this pull request? Or did I miss something? Or is this just AI slop? |
|
Fair question -- let me explain the intent and be transparent about what's original vs. derived. The two new files (ext-tcp-socket.js and tcp_socket.json) are based on the ones from 893-does-not-work-with-tb-115. I wanted to get the socket fix out in a reviewable form, separated from the other work on that branch (MV3 migration, SieveSpace refactor, parser rework, UI polish, bootstrap updates). What I added on top: What I deliberately left out: Testing: I tested it in TB 128 -- the extension loads, connects to a sieve server, StartTLS works, reload is clean. Unit tests pass. Re: "AI slop" -- I used Claude Code as a pair programmer to help research the TB API history and wire up the changes. The bug fixes above came out of actually running it and hitting errors. Also opened #1144 (hostname lookup: realHostName → hostName for TB 102+) and #1146 (AppImage tool download -- AppImageKit release 13 renamed assets with an obsolete- prefix). Those are independent of this PR. |
|
Still don't get what the intention behind this pull request should be? It just duplicates existing fixes which are already present in a different branch but it completely ignores any of the real blockers. The really really big blocker is that the graphical editor does not work reliably anymore in Thunderbird. The way drag an drop works changed slightly. Firefox adjusted his behavior to chrome and chrome to Firefox and thus events fire slightly different. Which results in elements being dropped at the wrong spot in Thunderbird. Thus the UI and the drag an drop editor can get out of sync. Which is the worst thing to happen for such an editor. Because what you see on the screen no more aligns with the script. Which is a pretty serious bug. And why I started a major parser rewrite. Additionally codemirror 5 is replaced by codemirror 6 and as the author writes nicely support is "slowly fading" and suffers from the same subtle bug due to bit-rot. And then there is the manifest V2 vs V3 dilemma. The Thunderbird devs try to maintain V2 compatibility as long as possible but if upstream breaks this addon will be basically dead. It needs a background service and experiments to work. |
|
Btw. the answer to your question was also generated by AI. |
Summary
Replaces the broken socket experiment API with one based on Thunderbird's internal TCPSocket component, fixing the extension for TB 115+ (fixes #893, fixes #934).
Background
The old
SieveSocketApi.jsusednsISocketTransportServiceandnsISSLSocketControl.StartTLS()directly. In TB 115+, StartTLS can only be triggered from the network thread while JS runs on the main thread, making the old approach impossible. Every major TB release since TB 24 has broken the socket API in some way.Approach
Uses the same
TCPSocketcomponent that Thunderbird itself uses for SMTP/IMAP (accessed viaCu.getGlobalForObject). The new experiment API is designed as a genericbrowser.tcpSocket.*API that aligns with the shape a future official WebExtension TCPSocket API might take.Changes
ext-tcp-socket.js) with race-prevention proxy pattern -- registers listeners before connecting to avoid threading races between WebExtension and network threadsSieveAbstractClient.isAlive(),SieveAbstractClient.startTLS(),SieveAbstractSession.isConnected()and all callersSieveUrl(TCPSocket expects integer port)browser.tcpSocket.*APIhasSocket()to prevent errors during extension reloadSieveSocketApi.jsandSieveSocketApi.jsonremoved (1042+ lines of broken code)Based on work from the
893-does-not-work-with-tb-115branch with bug fixes applied (Services.jsm removal, shutdownSockets typo, error handler variable shadowing, schema/implementation alignment).Test plan
npx gulp wx:packageabout:debugging-> Load Temporary Add-onnpm test(261 tests pass)