{"id":52616,"date":"2026-07-15T14:53:20","date_gmt":"2026-07-15T18:53:20","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=52616"},"modified":"2026-07-15T14:55:50","modified_gmt":"2026-07-15T18:55:50","slug":"spamsieve-3-3-1","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2026\/07\/15\/spamsieve-3-3-1\/","title":{"rendered":"SpamSieve 3.3.1"},"content":{"rendered":"<p><a href=\"https:\/\/c-command.com\/blog\/2026\/07\/15\/spamsieve-3-3-1\/\">SpamSieve 3.3.1<\/a> is an update of my Mac e-mail spam filter that improves the filtering accuracy and includes various optimizations, fixes, and updates for macOS 27. Some interesting engineering issues were:<\/p>\n\n<ul>\n<li><p>I&rsquo;m still supporting macOS 10.13, but the app can now build with the macOS 12 deployment target in preparation for Xcode 27. The way Swift handles calling deprecated APIs remains annoying. You need workarounds like protocols to suppress a warning in a particular region of code. Often, I <em>am<\/em> updating to a newer API, but I want to continue using the old one on earlier versions of macOS. Right now I am heavily testing on macOS 26, so I would like to <em>only<\/em> deploy the new code there. Sometimes the initial versions of APIs are buggy, and I don&rsquo;t want to have to retest every feature on every version. But Swift doesn&rsquo;t like me to gate the calls to macOS 26 and later if the new API was actually introduced in, say, macOS 11.<\/p><\/li>\n\n<li><p>The most risky update was probably switching to the Swift API for <code>Scanner<\/code>. This is tricky because the current scan position changes from being based on UTF-16 indexes to <code>String.Index<\/code>. And in some cases my code was intentionally scanning into the middle of a combining character. I was really glad to have extensive tests here.<\/p><\/li>\n\n<li><p>Recent versions of Tahoe introduced a Core Data bug that broke save recovery (when invalid Unicode can&rsquo;t be written to the database and we have to fix it up first). When the error comes in, SpamSieve looks under the <code>NSDetailedErrorsKey<\/code> key, but the value of this key is <code>\"NSDetailedErrorsKey\"<\/code> while the actual error info is under the key <code>\"NSDetailedErrors\"<\/code>.<\/p><\/li>\n\n<li><p>Database corruption combined with a Core Data bug and two Swift behaviors were causing crashes. The root problem, I think, is that in this situation Core Data neglects to set the error pointer for <code>-[NSManagedObjectContext countForFetchRequest:error:]<\/code>. Normally, Swift would detect this and throw a generic <code>nilError<\/code>. However, this method signals errors by returning <code>NSNotFound<\/code> instead of <code>nil<\/code>. It&rsquo;s annotated as <code>swift_error(nonnull_error)<\/code>, which I think means that Swift doesn&rsquo;t even look at the return value, only the (unset) error. So my code was receiving <code>NSNotFound<\/code> on the non-error path, treating it as a real count, and doing some math with it, which (by default in Swift) leads to a crash if there&rsquo;s overflow. Now my code checks for <code>NSNotFound<\/code> and uses <code>Int.addingReportingOverflow()<\/code>.<\/p><\/li>\n\n<li><p>I reimplemented Core Data batch fetching because of two problems with the <code>fetchBatchSize<\/code> option. First, it logs spurious errors when fetching from multiple stores at once. Second, it leads to high memory use. It will <em>load<\/em> objects in batches, but it never releases the earlier batches. You can manually refault objects that you no longer need, but it will still hold onto the full object shells, which can add up. My implementation only holds onto IDs, and it can fetch the IDs using a different context than the objects to push more work to background threads.<\/p><\/li>\n\n<li><p>I&rsquo;m now using <code>String.makeContiguousUTF8()<\/code> in various places to avoid slow iteration of bridged strings.<\/p><\/li>\n\n<li><p>There was a regression where some menu code could crash on macOS 10.13. <code>-[NSMenu setItemArray:]<\/code> is only available on macOS 10.14 and later, whereas the getter is always available. With old Objective-C, the two methods could be annotated with separate availabilities. The Objective-C property syntax doesn&rsquo;t allow this, so there&rsquo;s no way for the compiler to flag calls where the setter is missing.<\/p><\/li>\n\n<li><p>The AppleScript support works much better with large data sets. The key, I think, is to never return an array to Cocoa for a scripting property\/element. First, if you give it a lazy array it will sometimes try to access all the elements even if it only needs a few. And, second, AppleScript will run out of memory if the array is too large. By using indexed accessors, you can maintain laziness and only convert one object to a descriptor at a time. By caching a batch-fetching collection, you can limit the number of fetches and respond quickly when AppleScript requests individual objects.<\/p><\/li>\n\n<\/ul>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2026\/06\/09\/xcode-27-announced\/\">Xcode 27 Announced<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2026\/04\/13\/spamsieve-3-3\/\">SpamSieve 3.3<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/12\/05\/swift-proposal-precise-control-flags-over-compiler-warnings\/\">Swift Proposal: Precise Control Flags Over Compiler Warnings<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2024\/06\/04\/swift-at-10\/\">Swift at 10<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>SpamSieve 3.3.1 is an update of my Mac e-mail spam filter that improves the filtering accuracy and includes various optimizations, fixes, and updates for macOS 27. Some interesting engineering issues were: I&rsquo;m still supporting macOS 10.13, but the app can now build with the macOS 12 deployment target in preparation for Xcode 27. The way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2026-07-15T18:53:06Z","apple_news_api_id":"f406357b-449c-4580-94bb-4f368d18ca03","apple_news_api_modified_at":"2026-07-15T18:55:53Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAABA==","apple_news_api_share_url":"https:\/\/apple.news\/A9AY1e0ScRYCUu082jRjKAw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[159,131,109,863,46,30,32,2784,2742,54,138,71,372,901,258],"class_list":["post-52616","post","type-post","status-publish","format-standard","hentry","category-technology","tag-applescript","tag-bug","tag-coredata","tag-integer-overflow","tag-languagedesign","tag-mac","tag-macapp","tag-macos-27","tag-macos-tahoe-26","tag-objective-c","tag-optimization","tag-programming","tag-spamsieve","tag-swift-programming-language","tag-unicode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/52616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=52616"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/52616\/revisions"}],"predecessor-version":[{"id":52620,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/52616\/revisions\/52620"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=52616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=52616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=52616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}