Disable Remote Content in Junk Mail Folders

I just spent a whole afternoon trying to figure out how to get the stock Mail app to show images automatically except in the Junk folder(s). I finally got it, so I'm sharing my results here.

The Preferences pane (under "Viewing") gives the option to "Load remote content in messages" or not, regardless of the folder. (By default, it hides remote content, including images, in mail the app itself considers junk, but that is pretty limiting and will not play nicely with any external spam filtering.)

There did not appear to be any built in AppleScript support for changing this option without interacting with the preferences pane, but it turns out there is; it's just not officially documented. The option is called download html attachments in AppleScript. So, all you need is a couple of if actions to figure out whether to toggle the setting and a few lines of AppleScript to toggle it when necessary.

Here's my macro:

Note: one piece of this got cut off, namely the second if condition. The text that is cut off is:

^(General|Accounts|Junk Mail|Fonts & Colors|Viewing|Composing|Signatures|Rules)$

This prevents the setting from changing just because you have the Preferences open.

I hope this helps somebody else! Feedback is welcome.

Hey Ed,

Welcome to the forum!   :smile:

Here's my script for this job.

I activate/deactivate it with a keyboard shortcut.

-Chris

--------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2013/06/12 08:08
# dMod: 2021/01/10 08:30
# Appl: Apple Mail
# Task: Toggle Display Remote Images in HTML Mail
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Apple_Mail, @Mail, @Toggle, @Remote, @HTML, @Images
# Vers: 2.00
--------------------------------------------------------

try
   
   tell application "Mail"
      
      if (download html attachments) = true then
         
         set download html attachments to false
         set _notification to "Status == [OFF]"
         
      else if (download html attachments) = false then
         
         set download html attachments to true
         set _notification to "Status == [ON]"
         
      end if
   end tell
   
   display notification _notification with title "Load Images in HTML Messages" sound name "Tink"
   
on error e number n
   stdErr(e, n, true, true) of me
end try

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
   set e to e & return & return & "Num: " & n
   if beepFlag = true then
      beep
   end if
   if ddFlag = true then
      if n ≠ -128 then
         try
            tell application (path to frontmost application as text) ¬
               to set ddButton to button returned of ¬
               (display dialog e with title "ERROR!" buttons ¬
                  {"Copy Error Message", "Cancel", "OK"} ¬
                     default button "OK" giving up after 30)
            if ddButton = "Copy Error Message" then set the clipboard to e
         end try
      end if
   else
      return e
   end if
end stdErr
--------------------------------------------------------
1 Like

Very cool, Chris; thanks! I have a keyboard shortcut that currently just toggles the setting, without the notification or the error handling (AppleScript is still a bit new to me). I will have to play with this.

1 Like

I leave remote content disabled for all emails. A message may be wanted, not even junk, but I'm not interested in everyone having the option of monitoring what I've read. In my situation, many emails I receive with images aren't even images I need/want to see. But if I do, again, Keyboard Maestro makes it easy:

image

2 Likes

Thanks for sharing this; I somehow just discovered the Press Button action, and it has already been a life-changer.