Skip to content

#2019: on macOS, find pdfcraft-cli and photocraft-cli where Homebrew installs them - #2248

Merged
benandez merged 2 commits into
UCSLabs:mainfrom
easier-digital:fix/2019-pdfcraft-cli-macos
Dec 5, 2026
Merged

benandez merged 2 commits into
UCSLabs:mainfrom
easier-digital:fix/2019-pdfcraft-cli-macos

Conversation

@inluck

@inluck inluck commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2019

What changes for the person using MailCraft

On a Mac, File › Options now offers attachment previews when PdfCraft's or PhotoCraft's command-line tool was installed with Homebrew (brew install pdfcraft-cli, brew install photocraft-cli; both formulae are in homebrew-core).

Before, MailCraft looked in /Applications/<program>.app/Contents/MacOS and then on PATH, and neither finds a Homebrew install:

  • PdfCraft's Mac app doesn't include its CLI. Its packaging/macos/package.sh ships the CLI as a separate zip.
  • An app started from the Finder or the Dock gets launchd's short PATH, which doesn't include Homebrew's folders.

MailCraft now looks in /opt/homebrew/bin (Apple silicon) and then /usr/local/bin (Intel), after the app bundle and before PATH.

  • MAILCRAFT_PDFCRAFT_CLI and MAILCRAFT_PHOTOCRAFT_CLI still come first.
  • The lookup only finds the program: previews stay off until the owner turns them on.
  • PRIVACY.md names both folders.
  • A helper in the app bundle or a Homebrew folder that has none of its execute bits set (copied without them, say) is passed over, and the lookup goes on to the next folder, then PATH (vangel76's review).

Changes a default: no

How it was checked

  • New test attachment_render::tests::the_first_folder_that_has_the_helper_wins. With three folders (bundle, Apple silicon, Intel):

    • nothing is found while they're empty;
    • the Intel folder is found;
    • the Apple silicon folder wins over it;
    • the bundle wins over both;
    • a missing helper isn't found.

    It writes executable helpers and uses the platform's executable suffix, so it runs on every platform.

  • New test attachment_render::tests::a_helper_that_may_not_be_run_is_passed_over (Unix only): non-executable copies in the bundle and Apple silicon folders are passed over for a working one in the Intel folder, and with only a non-executable copy left nothing is found. It fails without the change.

  • macOS 26.6 (Apple silicon), Rust 1.98.1: cargo xtask ci passes all 15 steps with #2189: clippy passes on macOS: pin_for is used on Linux and FreeBSD alone #2190's pin_for fix applied locally. This branch doesn't include that fix.

  • Not tried end to end with Homebrew's own pdfcraft-cli installed, and not built on Windows or Linux.

  • cargo xtask ci passes

  • A crash or data-loss fix has its regression test (not one)

  • "Allow edits by maintainers": the fork belongs to an organisation, where GitHub doesn't offer that box. If you'd like to push to this branch, say so and you'll have write access to easier-digital/mailcraft.

  • I have signed the CLA, or will by commenting on this pull request

Human-reviewed, AI-assisted, nobody's mailbox harmed.

Summary by CodeRabbit

  • Bug Fixes
    • Attachment previews on macOS can now locate PdfCraft and PhotoCraft tools installed through Homebrew, including when MailCraft is opened from Finder or the Dock. MailCraft checks its app bundle first, then standard Homebrew locations, and finally PATH. Unusable tools are skipped so the search can continue to another available installation.

…mebrew installs them

PdfCraft's Mac app doesn't carry its CLI, and an app started from the
Finder or the Dock has launchd's short PATH, without Homebrew's folders, so
attachment previews were never offered on a Mac with the CLI installed by
`brew install pdfcraft-cli`. Look in /opt/homebrew/bin (Apple silicon) and
then /usr/local/bin (Intel), after the app bundle and before PATH.
PRIVACY.md names both folders.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@inluck
inluck requested a review from benandez as a code owner December 1, 2026 21:56
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

On macOS, MailCraft now checks /opt/homebrew/bin and /usr/local/bin for attachment-preview tools after checking the app bundle and before falling back to PATH. On Unix, it skips candidates that lack execute permission. Tests and documentation cover the search behavior.

Changes: macOS attachment-tool lookup

Layer / File(s) Summary
Search order and supporting coverage
apps/mailcraft/src/attachment_render.rs, apps/mailcraft/src/attachment_render_tests.rs, PRIVACY.md, packaging/release-notes.d/fixes/2019.md
The lookup checks the app bundle, then /opt/homebrew/bin and /usr/local/bin, before falling back to PATH. On Unix, it skips candidates without execute permission. Tests cover directory precedence, missing helpers, and non-executable helpers. Documentation describes the search locations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested reviewers: kad26

Merge Risk: Minimal · up to 09407 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: on macOS, MailCraft now finds the pdfcraft-cli and photocraft-cli helpers in the Homebrew install folders. The raw summary confirms that the change adds the /opt/homeb…
Linked Issues check Passed [#2019] The issue requires that MailCraft on macOS finds pdfcraft-cli and photocraft-cli when Homebrew installs them in /opt/homebrew/bin (Apple silicon) or /usr/local/bin (Intel). The PR adds both fo…
Out of Scope Changes check Passed All changed files relate to #2019. attachment_render.rs adds the Homebrew lookup and the new first_in and runnable helpers. attachment_render_tests.rs adds tests for that lookup, including the execute…
Description check Passed The description follows the repository template. It states the user-facing change clearly: on a Mac, attachment previews now work when the PdfCraft or PhotoCraft CLI is installed with Homebrew. It lin…
Full details: Title check

Explanation

The title names the main change: on macOS, MailCraft now finds the pdfcraft-cli and photocraft-cli helpers in the Homebrew install folders. The raw summary confirms that the change adds the /opt/homebrew/bin and /usr/local/bin lookup in attachment_render.rs, with matching tests and docs. The '#2019' prefix is an issue reference and is acceptable, though it is not descriptive on its own.

Full details: Linked Issues check

Explanation

[#2019] The issue requires that MailCraft on macOS finds pdfcraft-cli and photocraft-cli when Homebrew installs them in /opt/homebrew/bin (Apple silicon) or /usr/local/bin (Intel). The PR adds both folders to the macOS lookup in apps/mailcraft/src/attachment_render.rs. The lookup order is: app bundle, then the two Homebrew folders, then PATH. The MAILCRAFT_PDFCRAFT_CLI and MAILCRAFT_PHOTOCRAFT_CLI overrides still come first. The later commit adds a runnable check on Unix. It skips a discovered file that has no execute bit and continues to the next folder. This does not remove the Homebrew lookup. It changes only which files qualify, so a non-executable file no longer blocks a later valid helper. The test attachment_render_tests.rs covers folder order, missing helpers, and skipping of non-executable helpers. The issue's optional alternatives (ArtCraft Launcher paths, bundling the CLI in PdfCraft.app) are not required by the issue wording ('and/or'). Evidence comes from the change summaries. The source was not read directly. End-to-end testing with Homebrew's pdfcraft-cli was not performed, which is a verification gap and not a coding requirement.

Full details: Out of Scope Changes check

Explanation

All changed files relate to #2019. attachment_render.rs adds the Homebrew lookup and the new first_in and runnable helpers. attachment_render_tests.rs adds tests for that lookup, including the execute-bit case. PRIVACY.md names the two folders, which matches the new lookup. packaging/release-notes.d/fixes/2019.md documents the fix. The execute-bit check applies to the existing app bundle candidate as well as the Homebrew candidates. This is a small change to existing bundle lookup behavior, but it is part of the same shared helper and is covered by a test, so it is connected to the objective. The summary does not show a default change. The PR states that finding a CLI does not enable previews. The #2190 pin_for fix is only a local test condition and is not in this branch. docs/log.d/ROADMAP/progress/2019.md is excluded by the '!docs/**' rule and was not reviewed.

Full details: Description check

Explanation

The description follows the repository template. It states the user-facing change clearly: on a Mac, attachment previews now work when the PdfCraft or PhotoCraft CLI is installed with Homebrew. It links issue #2019, lists the new lookup order (app bundle, /opt/homebrew/bin, /usr/local/bin, then PATH), and explains the executable-bit filter. It gives the checks run: a new cross-platform test, a Unix-only test, and a macOS 26.6 run of cargo xtask ci. It also states what was not tested. The CLA box is ticked. The 'Changes a default' line is present. The 'Allow edits by maintainers' box is unticked, and the author explains why. The 'crash or data-loss fix' item is unticked and marked not applicable. Minor gaps: the template's 'Closes #' reference uses #2019 while the objectives cite PR #2248, which is a discrepancy to verify but not a description defect. The description also depends on #2190's pin_for fix, which is not in this branch, and the author notes that.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 75e2258 and 0940720.

Files ignored due to path filters: 1

  • docs/log.d/ROADMAP/progress/2019.md is excluded by !docs/**
Files selected for processing: 2

  • apps/mailcraft/src/attachment_render.rs
  • apps/mailcraft/src/attachment_render_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@vangel76 vangel76 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked renderer discovery, macOS candidate order, preview availability and process launch, the path-order tests, and current main.

Source review only. I did not build the project, run tests, or check CI.

Comment thread apps/mailcraft/src/attachment_render.rs Outdated

/// The helper `name` in the first of `dirs` that has it.
fn first_in(dirs: impl IntoIterator<Item = PathBuf>, name: &str) -> Option<PathBuf> {
dirs.into_iter().map(|dir| dir.join(name)).find_map(absolute_file)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3. Skip non-executable files in Homebrew's helper locations

A non-executable PDFCraft CLI left in /usr/local/bin, for example after copying it without execute permissions, now wins over a working copy on PATH. absolute_file accepts any regular file, so Options offers previews, but the selected helper fails at process launch. On macOS, skip auto-discovered candidates without execute permission and continue the lookup. Update the path-order test to use executable helpers and include a non-executable earlier candidate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Fixed in 0940720: first_in now passes over a helper with none of its execute bits set and looks in the next folder, then on PATH. The path-order test writes executable helpers, and a new test, a_helper_that_may_not_be_run_is_passed_over (Unix only), puts non-executable copies in the bundle and Apple silicon folders ahead of a working one in the Intel folder. It fails without the change.

Human-reviewed, AI-assisted, nobody's mailbox harmed.

A pdfcraft-cli without execute permission in /usr/local/bin, copied
there without it, say, was taken over a working copy on PATH:
absolute_file takes any regular file, so Options offered previews,
and the helper then failed as it was started (vangel76 on UCSLabs#2248).

first_in, which looks in the app bundle and Homebrew's folders, now
passes over a file with none of its execute bits set and looks in
the next folder, then on PATH. The path-order test writes executable
helpers, and a_helper_that_may_not_be_run_is_passed_over puts
non-executable copies ahead of a working one.

Human-reviewed, AI-assisted, nobody's mailbox harmed.
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@vangel76 vangel76 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified that the macOS lookup now passes over helper files with no execute bits and continues to the remaining locations. The source test includes an earlier non-executable file and a working helper later in the lookup.

Source review only. I did not build the project, run tests, or check CI.

@benandez
benandez added this pull request to the merge queue Dec 5, 2026
Merged via the queue into UCSLabs:main with commit 29734af Dec 5, 2026
17 checks passed
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.

macOS: attachment preview is never offered – pdfcraft-cli isn't where MailCraft looks

3 participants