0

I am developing an email client using PHP. I have got a problem with mark my emails as spam because php library imap doesn't support mark as spam when I mark the emails as a spam. The only things I can see which it can set the emails as flagged which is not a good thing. When I send the spam emails to my server after I set the emails as flagged, I will still get the spam emails in my inbox.

However, I did a quick research and it said that I would need to use spamassassin to set up the rules. I have got spamassassin installed on my server, but I have got no idea how to use it.

Do you know how I could mark my emails as spam using PHP API to set up the rules on spamassassin?

When I set up the rules on spamassassin to mark my emails as spam, will my emails go straight to spam next time when I send the emails?

Thank you.

Robert Jones
  • 390
  • 3
  • 18
  • (I have no idea). Does it help moving the items to the JUNK folder? (So the server learns that this email is spam) – paskl Jul 29 '19 at 22:55
  • @paskl Well no it doesn't help moving the emails to the JUNK folder as it didn't help the server to learns that the emails is spam when I set the emails as flagged and move to junk folder. Any idea? – Robert Jones Jul 29 '19 at 22:59
  • 1
    your client can look at the headers and act accordingly. at least i think that's what you are asking –  Jul 29 '19 at 22:59
  • @tim Do you mean the spamassassin can look at the headers and act according? – Robert Jones Jul 29 '19 at 23:01
  • 1
    no your client. –  Jul 29 '19 at 23:03
  • @tim Oh I see, well I don't know how I can get the client to look at the headers and act according. As I have set up the mail client using PHP to display the list of emails and read my emails. – Robert Jones Jul 29 '19 at 23:05
  • @tim if you could help me how I could set up the mail client to act according to move my emails to junk folder using PHP that would be great. – Robert Jones Jul 29 '19 at 23:07
  • imap_fetchheader should have the attached headers you can filter on –  Jul 29 '19 at 23:13
  • @tim like what? if you can give me an example that would be great. thank you. – Robert Jones Jul 29 '19 at 23:56

1 Answers1

0

Do you know how I could mark my emails as spam using PHP API to set up the rules on spamassassin?

Automated learning of spam is done, in SA, via a Bayesian classifier. The training tool is sa-learn and you can pipe messages into it through STDIN.

When I set up the rules on spamassassin to mark my emails as spam, will my emails go straight to spam next time when I send the emails?

No.

You need to configure your MDA to both:

  • Pass emails through SpamAssassin so that it gets spam classification headers added to the existing email headers
  • Read those headers and deliver the email to somewhere that isn't the INBOX

For example, my MDU is configured to run incoming mail through Procmail and my ~/.procmailrc includes:

:0
* ^X-Spam-Level: \*\*\*\*\*\*\*\*
/dev/null

:0:
* ^X-Spam-Level: \*\*\*
$HOME/Maildir/.Junk/
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thank you for your post. I think I get where you are coming from. So if I write something like this `if $isSpam->isSpam($message) { ...move the email to spam folder }`? It will check with spamassassin that if the email is spam then it will move to junk\spam folder before I see the list of my emails? is that correct? – Robert Jones Jul 30 '19 at 15:17
  • Generally, you would want to do this in your MDU and not your email client. – Quentin Jul 30 '19 at 15:26
  • What is MDU? how do I send the data to MDU using php api to let them know that the email I receive is spam? – Robert Jones Jul 30 '19 at 16:03
  • The Mail Delivery Agent. You don't send data to the MDU to mark it as spam. If you want your email client to mark something as spam (i.e. when the user clicks "This is spam") then you pass it through `sa-learn` and move it to the Junk folder. The MDU passes the incoming email through SpamAssassin to *automatically* mark it as spam based on the training you've given it. – Quentin Jul 30 '19 at 16:06
  • Oh I see, so can I use php api to call `sa-learn` to mark the emails as spam and move to the junk folder? next time when I receive the similar emails will it move to the junk folder automatically after I marked the emails as spam? – Robert Jones Jul 30 '19 at 16:11
  • 1
    Calling `sa-learn` trains the Bayesian classifier. Moving the email is a separate thing you have to do. Moving to junk automatically will only happen if you configure your MDU as described in the second half of this answer (and only after the Bayesian classifier is sufficiently trained). – Quentin Jul 30 '19 at 16:14