- MacOS 15.4.1
- SpamSieve 3.1.2 with licence. Running.
- eM Client 10.3 with licence. Running.
- AppleMail should never be active.
There is no supported way to connect SpamSieve and eM Client.
I made a Python script to connect to the email server.
mail = imaplib.IMAP4_SSL(SMTP_SERVER)
After some steps I can give SpamSieve one email to check.
r = requests.post(“http://localhost:2000/spamsieve”, data={“message”: raw_email})
Unfortunately, SpamSieve does not start an HTTP server.
defaults write com.c-command.SpamSieve AllowRemoteControl -bool true
doesn’t help.
How to start the server? How to connect to it?
Is there another API?
SpamSieve does not have an HTTP API on that port, nor an AllowRemoteControl
setting. I’m not sure where you found those…
However, it does have an AppleScript API. You could do something like this:
import subprocess, tempfile, os
# Fill these in with info from your IMAP server
sourceBytes = b""
accountName = "MyAccountName"
mailboxName = "MyMailboxName"
# Message may be larger than the argument or environment limit, and there's seemingly no way to pass to AppleScript via stdin these days, so write a temporary file
fd, path = tempfile.mkstemp(".eml", "MessageForSpamSieve")
with os.fdopen(fd, "wb") as file:
file.write(sourceBytes)
appleScript = """
on run _argv
set {_path, _accountName, _mailboxName} to _argv
-- Read without encoding so the "string" gets passed to SpamSieve without changing the bytes
set _file to open for access _path
set _source to read _file
close access _file
tell application "SpamSieve"
-- Change to true if you will be correcting mistakes, either via another script or SpamSieve’s Log window
set _autoTraining to false
set _origin to {source identifier:"com.yourdomain.imap-script"}
set _origin to _origin & {application name:"YourScriptName"}
set _origin to _origin & {application version:"1.0"}
set _origin to _origin & {mail account type:"IMAP"}
set _origin to _origin & {mail account name:_accountName}
set _origin to _origin & {mailbox name:_mailboxName}
set _score to score message _source auto training _autoTraining origin _origin
return _score
end tell
end run
"""
args = [
"/usr/bin/osascript",
"-e", appleScript,
path,
accountName,
mailboxName
]
completedProcess = subprocess.run(args, capture_output=True)
if completedProcess.returncode == 0:
scoreBytes = completedProcess.stdout
score = int(str(scoreBytes, "utf-8"))
if score >= 50:
print("Message is spam")
else:
print("Message is good")
else:
print("Error:", completedProcess.stderr)
os.remove(path)