Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Let a Mail plug-in go with the app that installed it

Țugui Dragoșf6c03d66c386
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
index 78e72fc4..71786aff 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGuard.swift
@@ -133,7 +133,9 @@ struct RemovalGuard: Sendable {
guard !exclusions.excludes(spellings: spellings), !exclusions.holds(spellings: spellings) else {
return .excluded
}
- if let refusal = protectedObjects.refusal(of: name) { return refusal }
+ if !ProtectedData.isAMailPlugIn(name, home: home), let refusal = protectedObjects.refusal(of: name) {
+ return refusal
+ }
// The rules the helper follows. They protect every account's keychain and mail, not only those of the
// account Peel runs in.
guard !ProtectedData.refuses(spellings: spellings, home: home) else { return .protectedLocation }
@@ -146,7 +148,8 @@ struct RemovalGuard: Sendable {
guard !isUnderAPrefix || Self.isAToolsLink(spelling, isALink: isALink) else { return .protectedLocation }
let parts = PathComponents.of(spelling)
- guard !protectedTrees.contains(where: { parts.starts(with: $0) }) else { return .protectedLocation }
+ let isATree = protectedTrees.contains { parts.starts(with: $0) }
+ guard !isATree || ProtectedData.isAMailPlugIn(spelling, home: home) else { return .protectedLocation }
// Also refuse a folder with a protected tree inside, since removing it would take the tree along.
guard !protectedTrees.contains(where: { $0.count > parts.count && $0.starts(with: parts) }) else {
return .holdsProtectedData
diff --git a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
index d97fbd03..95f67caf 100644
--- a/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
+++ b/Packages/PeelCore/Sources/PeelPrivileged/ProtectedData.swift
@@ -471,6 +471,19 @@ public enum ProtectedData: Sendable {
return [path]
}
+ /// True for a Mail plug-in directly in a home's `Library/Mail/Bundles`, or anything inside one: the one thing in
+ /// Mail's folder that holds no mail: it is code, and Apple said Mail plug-ins stop working in a later macOS
+ /// (WWDC21 session 10168).
+ public static func isAMailPlugIn(_ path: String, home: String) -> Bool {
+ let folders = spellings(of: home).map { PathComponents.of($0) + ["library", "mail", "bundles"] }
+ return privateNames(of: path).contains { spelling in
+ let names = PathComponents.of(spelling.lowercased())
+ return folders.contains { bundles in
+ names.count > bundles.count && names.starts(with: bundles) && names[bundles.count].hasSuffix(".mailbundle")
+ }
+ }
+ }
+
/// True for a path at or inside anything protected here: the home and system folders, the keys, a wallet
/// extension's storage, a media library, a global preferences file, or one of Apple's group containers.
/// Running as root, the helper can see every account on the Mac, so a home folder is any folder directly
@@ -488,7 +501,7 @@ public enum ProtectedData: Sendable {
if isInsideAWalletExtension(names) { return true }
for home in homes(of: names, given: home) where trees(under: home).contain(names) {
- return true
+ if !isAMailPlugIn(spelling, home: home) { return true }
}
return systemFolderNames.contains { names.starts(with: $0) }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
index 2b6bc49d..d3580a48 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/AttackRemovalGuardTests.swift
@@ -382,6 +382,50 @@ struct AttackRemovalGuardTests {
#expect(guardian.allowsRemoval(of: cache.deletingLastPathComponent()))
}
+ /// Only a Mail plug-in, which holds code and no mail, may leave Mail's folder: what is around it, and a link that
+ /// makes mail look like one, stay.
+ @Test func onlyAMailPlugInMayLeaveMailsFolder() throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ let plugIn = try directory.directory("home/Library/Mail/Bundles/Mailer.mailbundle/Contents")
+ .deletingLastPathComponent()
+ let message = try directory.file("home/Library/Mail/V10/INBOX.mbox/Messages/1.emlx")
+ let disguised = try directory.directory("home/Library/Mail/V10/Disguised.mailbundle")
+ try directory.directory("home/Library/Mail/Elsewhere")
+ try link(
+ home.appending(path: "Library/Mail/V10").path(percentEncoded: false),
+ at: home.appending(path: "Library/Mail/Elsewhere/Bundles").path(percentEncoded: false)
+ )
+ let guardian = RemovalGuard(
+ environment: SearchEnvironment(homeDirectory: home, rootDirectory: directory.url.appending(path: "root"))
+ )
+
+ #expect(guardian.allowsRemoval(of: plugIn))
+ #expect(guardian.allowsRemoval(of: plugIn.appending(path: "Contents")))
+ for item in [
+ message, disguised, plugIn.deletingLastPathComponent(), home.appending(path: "Library/Mail"),
+ home.appending(path: "Library/Mail/Elsewhere/Bundles/Disguised.mailbundle"),
+ ] {
+ #expect(!guardian.allowsRemoval(of: item), "ATTACK SUCCEEDED: \(item.path(percentEncoded: false)) may be removed")
+ }
+ }
+
+ @Test func aMailFolderLinkedInPlaceOfBundlesIsNoPlugIn() throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ try directory.directory("home/Library/Mail/V10/Inbox.mailbundle/Messages")
+ try link(
+ home.appending(path: "Library/Mail/V10").path(percentEncoded: false),
+ at: home.appending(path: "Library/Mail/Bundles").path(percentEncoded: false)
+ )
+ let guardian = RemovalGuard(
+ environment: SearchEnvironment(homeDirectory: home, rootDirectory: directory.url.appending(path: "root"))
+ )
+
+ let disguised = home.appending(path: "Library/Mail/Bundles/Inbox.mailbundle")
+ #expect(!guardian.allowsRemoval(of: disguised), "ATTACK SUCCEEDED: mail moved as a Mail plug-in through a link")
+ }
+
/// A blockchain can outgrow the startup disk, so a wallet's folder is often kept on another one, with a link to it
/// where the wallet looks. Its keys have to be known under the name of the disk they are on too.
@Test func aWalletKeptOnAnotherDiskThroughALink() throws {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 363892ff..e7597e4b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -989,8 +989,7 @@ struct LeftoverScannerTests {
#expect(scan.leftovers.allSatisfy { $0.kind == .plugIns })
}
- /// All of Mail in the home's Library is protected, so a Mail bundle is left out rather than offered and refused.
- @Test func leavesOutTheAppsMailBundle() async throws {
+ @Test func findsTheAppsMailBundle() async throws {
let directory = try TemporaryDirectory()
let app = InstalledApp(
url: URL(filePath: "/Applications/Mailer.app"), bundleIdentifier: "org.example.mailer", name: "Mailer"
@@ -1002,7 +1001,8 @@ struct LeftoverScannerTests {
let scan = await LeftoverScanner(environment: environment(in: directory)).scan(app, installedApps: [app])
- #expect(scan.leftovers.map(\.url.lastPathComponent) == ["org.example.mailer"])
+ #expect(Set(scan.leftovers.map(\.url.lastPathComponent)) == ["Mailer.mailbundle", "org.example.mailer"])
+ #expect(scan.leftovers.first { $0.url.lastPathComponent == "Mailer.mailbundle" }?.match.isRecommended == true)
}
/// A plug-in is named for what it does, so when its name matches nothing, the identifier in its `Info.plist`
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
index 376a2245..539ef146 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/OrphanScannerTests.swift
@@ -529,7 +529,7 @@ struct OrphanScannerTests {
#expect(Set(scan.groups.flatMap(\.items).map(\.url.lastPathComponent)) == ["Gone.vst3", "Gone Reverb.component"])
}
- @Test func leavesOutAMailBundleOfAnAppThatLeft() async throws {
+ @Test func listsAMailBundleOfAnAppThatLeft() async throws {
let directory = try TemporaryDirectory()
let info = """
<?xml version="1.0" encoding="UTF-8"?>
@@ -544,7 +544,7 @@ struct OrphanScannerTests {
let scan = await scanner(in: directory).scan(installedApps: installed, remembered: [gone])
- #expect(scan.groups.flatMap(\.items).map(\.url.lastPathComponent) == ["org.example.mailer"])
+ #expect(Set(scan.groups.flatMap(\.items).map(\.url.lastPathComponent)) == ["Mailer.mailbundle", "org.example.mailer"])
}
/// Below the top of a place a dotted name is often a lock or a backup, so only what came with a gone app counts.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
index dba33784..7ed4f509 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
@@ -330,13 +330,13 @@ struct PackageReceiptsTests {
#expect(receipt.items.isEmpty)
}
- /// A receipt can name a path `RemovalGuard` refuses, such as a file in `/usr/local/bin` or a Mail bundle.
+ /// A receipt can name a path `RemovalGuard` refuses, such as a file in `/usr/local/bin` or one inside Mail.
/// Such an item is listed and left alone, rather than offered and then refused at the move.
@Test func leavesAloneWhatTheGuardWouldRefuse() async throws {
let directory = try TemporaryDirectory()
let volume = PathPattern.canonical(directory.url).path(percentEncoded: false)
let app = PathPattern.canonical(try directory.directory("Applications/Example.app"))
- let rules = PathPattern.canonical(try directory.directory("home/Library/Mail/Bundles/Example.mailbundle"))
+ let rules = PathPattern.canonical(try directory.directory("home/Library/Mail/V10/MailData/Example"))
let info = try #require(String(
data: PropertyListSerialization.data(fromPropertyList: ["volume": volume, "install-location": ""], format: .xml, options: 0),
encoding: .utf8
@@ -345,7 +345,7 @@ struct PackageReceiptsTests {
switch arguments.first {
case "--pkgs-plist": PkgutilAnswer.packages("com.example.pkg")
case "--pkg-info-plist": info
- case "--files": "Applications/Example.app\nhome/Library/Mail/Bundles/Example.mailbundle\n"
+ case "--files": "Applications/Example.app\nhome/Library/Mail/V10/MailData/Example\n"
default: ""
}
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PluginsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PluginsTests.swift
index a7563b6f..c250be07 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PluginsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PluginsTests.swift
@@ -79,9 +79,7 @@ struct PluginsTests {
])
}
- /// All of Mail in the user's own Library is protected, so a Mail bundle there is listed but never offered: moving
- /// it would only be refused. A plug-in anywhere else is offered as usual.
- @Test func showsAMailBundleInTheUsersLibraryButLeavesItAlone() async throws {
+ @Test func offersAMailBundleInTheUsersLibrary() async throws {
let directory = try TemporaryDirectory()
try directory.directory("home/Library/Mail/Bundles/Example.mailbundle/Contents")
try directory.directory("home/Library/Audio/Plug-Ins/VST3/Synth.vst3/Contents")
@@ -92,7 +90,7 @@ struct PluginsTests {
let plugins = await Plugins.scan(environment: environment)
- #expect(try #require(plugins.first { $0.category == .mailBundles }).refusal == .protectedLocation)
+ #expect(try #require(plugins.first { $0.category == .mailBundles }).refusal == nil)
#expect(try #require(plugins.first { $0.category == .vst3 }).refusal == nil)
}
diff --git a/SAFETY.md b/SAFETY.md
index c7776ffa..1bff9511 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -27,7 +27,7 @@ In the Library of every account on the Mac and, for the last rows, in the home f
| `Application Support/MobileSync` | iPhone and iPad backups. |
| `Application Support/AddressBook`, `Contacts` | Your contacts. |
| `Application Support/CallHistoryDB` | Your call history. |
-| `Mail`, `Messages` | Your mail and your messages. |
+| `Mail`, `Messages` | Your mail and your messages. A Mail plug-in in `Mail/Bundles`, which holds code and no mail, may go. |
| `Safari` | Bookmarks, history, reading list. |
| `Calendars`, `Reminders` | Your calendars and reminders, where older systems kept them. |
| `Group Containers/` any of Apple's own | Where macOS 26 keeps notes, reminders, calendars, voice memos, the journal, and more. Apple moves these between releases, so they are recognized by their name (`com.apple.` after an optional team and an optional `group.`, `groups.`, or `systemgroup.`), not from a list. |