mail rules
I have mail rules setup to add what i deem as junk to be read and deleted amongst other rules I hit apply in addition to syncing mailbox but my rules are not working as designed or setup.
iMac 21.5", macOS 10.13
I have mail rules setup to add what i deem as junk to be read and deleted amongst other rules I hit apply in addition to syncing mailbox but my rules are not working as designed or setup.
iMac 21.5", macOS 10.13
[Continuation due to 5000 character limit]
From your Dock, select Launchpad : Other : Script Editor.
Copy/paste all of the following code into the Script Editor:
-- return-path.applescript
-- Select a given message item in Apple Mail, and then run this script. It will produce a dialog
-- showing the sender's From and Return-Path addresses. Copy the entire Return-Path
-- string into the right-window of an Apple Mail rule.
-- This script *does not* alter, or remove individual email messages.
-- VikingOSX, 2019-10-23, Apple Support Communities, No warranties of any kind
use framework "Foundation"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions
property NSString : a reference to current application's NSString
property NSRegularExpression : a reference to current application's NSRegularExpression
property NSRegularExpressionCaseInsensitive : a reference to current application's NSRegularExpressionCaseInsensitive
tell application "Mail"
if not it is running then activate
if not (get selection) is {} then
set theMsg to item 1 of (get selection)
else
return
end if
tell theMsg
set theSender to its sender
set theHDR to its all headers
end tell
end tell
set rtnpath to my return_address(theHDR) as text
set fmsg to "Sender Address:" & return & theSender & return & return & ¬
"Return-Path:" & return & rtnpath
display dialog fmsg with title "Current Mail Item Addresses"
return
on return_address(atxt)
set hstr to NSString's alloc()'s initWithString:atxt
set pattern to "(?<=Return-Path:|Return-path:)\\s+(<.*?>).*"
set regex to NSRegularExpression's regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive |error|:0
set hrange to current application's NSMakeRange(0, hstr's |length|())
set matches to (regex's firstMatchInString:hstr options:0 range:hrange)
if matches = "" then return "Not Found"
set matchrange to matches's rangeAtIndex:1
return (hstr's substringWithRange:matchrange) as text
end return_address
In the Script Editor, click the compile (hammer) icon, and the purple text will change colors indicating that it has no compile issues. Open Apple Mail, and select a single message item from a known SPAM source, and then click the Run button in the Script Editor.
You can save this script to your Desktop as either a script, script bundle, or Application through the Script Editor's Save panel. Then you double-click the Desktop item when you have a Mail item selected.
[Continuation due to 5000 character limit]
From your Dock, select Launchpad : Other : Script Editor.
Copy/paste all of the following code into the Script Editor:
-- return-path.applescript
-- Select a given message item in Apple Mail, and then run this script. It will produce a dialog
-- showing the sender's From and Return-Path addresses. Copy the entire Return-Path
-- string into the right-window of an Apple Mail rule.
-- This script *does not* alter, or remove individual email messages.
-- VikingOSX, 2019-10-23, Apple Support Communities, No warranties of any kind
use framework "Foundation"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions
property NSString : a reference to current application's NSString
property NSRegularExpression : a reference to current application's NSRegularExpression
property NSRegularExpressionCaseInsensitive : a reference to current application's NSRegularExpressionCaseInsensitive
tell application "Mail"
if not it is running then activate
if not (get selection) is {} then
set theMsg to item 1 of (get selection)
else
return
end if
tell theMsg
set theSender to its sender
set theHDR to its all headers
end tell
end tell
set rtnpath to my return_address(theHDR) as text
set fmsg to "Sender Address:" & return & theSender & return & return & ¬
"Return-Path:" & return & rtnpath
display dialog fmsg with title "Current Mail Item Addresses"
return
on return_address(atxt)
set hstr to NSString's alloc()'s initWithString:atxt
set pattern to "(?<=Return-Path:|Return-path:)\\s+(<.*?>).*"
set regex to NSRegularExpression's regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive |error|:0
set hrange to current application's NSMakeRange(0, hstr's |length|())
set matches to (regex's firstMatchInString:hstr options:0 range:hrange)
if matches = "" then return "Not Found"
set matchrange to matches's rangeAtIndex:1
return (hstr's substringWithRange:matchrange) as text
end return_address
In the Script Editor, click the compile (hammer) icon, and the purple text will change colors indicating that it has no compile issues. Open Apple Mail, and select a single message item from a known SPAM source, and then click the Run button in the Script Editor.
You can save this script to your Desktop as either a script, script bundle, or Application through the Script Editor's Save panel. Then you double-click the Desktop item when you have a Mail item selected.
I made a custom mail to handle SPAM from one particular address. One sets their Mail rule to acton on any Return-path that matches that server address. I get about 30 spams a day from several different named sources that share the same server, and one mail rule automatically redirects this junk into my Trash On My Mac folder. The rule that does this is:
Now, Return-Path does not exist by default in the list of selectable From list items, so it has to be added. At the very bottom of the long menu you get when you click that first selector, is a Edit header list… entry.
You select that, and a panel opens that shows your existing From items, and you press the [+] to add Return-Path to the Header items, and it is entered just like this:
Click Ok, then you can select that Header item as shown in my first screenshot.
I have written a short AppleScript that displays a dialog of the selected mail item's sender's email address, and their Return-Path server address which you want to copy and paste into the third field as I have done above. Save the rule. If there are any emails that have this Return-Path server in their header, they should be immediately processed as soon as you save the rule.
An example of the dialog produced by the AppleScript using bogus addresses so the Apple hosts won't delete it due to privacy concerns:
You want to copy the entire (including <> characters) of the Return-Path address shown for your rule match.
See my next post for the AppleScript code to produce the preceding dialog.
roxanne133 wrote:
I have mail rules setup to add what i deem as junk to be read and deleted amongst other rules I hit apply in addition to syncing mailbox but my rules are not working as designed or setup.
Mail rules, see if there is any thing here:
Use rules to manage emails you receive in Mail on Mac ...
Set up rules to filter email in Mail on iCloud.com - Apple Support
Additionally competing Junk mail :
https://support.apple.com/guide/mail/if-junk-mail-filters-arent-working-mlhlp1145/mac
https://support.apple.com/guide/mail/junk-mail-preferences-cpmlprefjunk/mac
https://support.apple.com/guide/mail/reduce-junk-mail-mlhlp1065/mac
Identify and filter junk mail in iCloud - Apple Support
https://support.apple.com/en-in/guide/mail/junk-mail-advanced-settings-cpmlprefjunkadd/mac
https://support.apple.com/en-in/guide/mail/viewing-preferences-cpmlprefview/mac
If you expect help debugging your Mail Rules you'll need to post them.
Not knowing your system environment, context, or rules, it is hard to
help you. Please help us to help you by posting some details.
I set up rules to delete continuous mail I get even though I’ve unsubscribed I also setup rules for business emails to go to certain folders and personal but when I hit apply it doesn’t work my mailbox is still cluttered and unorganized.
mail rules