Learning Search

IFTTT / Reddit Alerts Filling Up With Porn Spam? Here’s What To Do

A little over five years ago I wrote an article called Keeping Up With Reddit: Use IFTTT, Not Google Alerts. While I don’t use Reddit as a social network, it has been invaluable for keeping me informed about new resources, especially from smaller creators who might not have the resources to do a big rollout with press releases and so forth.

That article includes this comment: “What about spam? – Personally, I haven’t seen much spam on the Reddit resources I get. I think my keywords are keeping most of it at bay.”

That quote did not age well.

In the last few weeks my Reddit/IFTTT notifications have been overrun with pornography spam. Not just text but pictures of people doing things I don’t want to look at with body parts I don’t want to look at. Having to slog through that makes it difficult to get to my meaningful email.

Initially I thought I would be unable to completely solve this problem and would have to live with unsolicited tonkers, but I fixed it entirely. Tonkers 100% gone. How’d I do it? Read on!

(PLEASE NOTE: This article assumes you know what IFTTT is and how to make IFTTT applets. If you don’t, check out this huge, downloadable guide to IFTTT, from MakeUseOf.)

(ALSO PLEASE NOTE: I hope this goes without saying but if you’re a grown adult and want to look at pornography it’s fine with me. I don’t and I don’t like it showing up in my email.)

My Reddit Spam Problem

While I was putting this article together, I got an example of this Reddit spam clean enough that I can post a screenshot without censoring 90% of it (some words were censored along with a naked rear end and the guy’s face.) I also highlighted an important part of the subject line.

If these porn emails were all the same, then it would be easy to filter them out. But each of them is much like this one – a range of keywords, some not in English, and sometimes an image. There is no single keyword that I can use to filter all of this spam out. (And Gmail is not helping; issues of ResearchBuzz regularly end up in my spam bin while the Reddit porn spam has no trouble making it to my inbox.)

One thing I noticed with this and the other Reddit spam is the subreddit: /r/u_guicepdeo1993 . The u_ is not a regular part of most subreddits I see. Taking a quick look at the other spams, I noticed that the subreddit style seems to be consistent. Here are three examples:

/r/u_muscperssing1980

/r/u_ticdime1991

/r/u_unarhot1990

As I understand it, that u_ as part of a subreddit’s name means it’s a subreddit that’s attached to a user account. I think they’re made automatically; here’s mine for ResearchBuzz: reddit.com/r/u_researchbuzz .

When it comes to Reddit monitoring, the personal subreddits do not provide useful resources, as I discovered when I reviewed a group of useful, non-spam Reddit alerts. Therefore, if I could filter out this subreddit pattern — the /r/u_ that appeared in every spammy email — I could eliminate most/all of my pornography spam without missing much if any meaningful content.

The logical next step was looking for a place to put that spam-catching filter.

Looking for a Place to Put a Filter

Gmail filters by entire words and only entire words as far as I know. If I wanted to create a Gmail filter that sent every email containing the subreddit name /r/u_muscperssing1980 to my Trash folder, I could do that. But I can’t filter by words that contain the string /r/u_, because Gmail does not support stemming, a search feature that allows you to find keywords based on a common string at the beginning (the “stem”.) Unless I want to gather up all the spam-sending subreddit names and manually add them to my Gmail filters (and who has time to do that?), Gmail is not going to help me in filtering out this spam.

I then checked at Reddit to see if there was some way I could change my search to limit my exposure to spam. The keyword that seems to attract the most junk is archive, but it’s such a useful keyword! It finds me so many good things and I am not willing to make it more specific. So adding more keywords to my search query was out, but I was hoping that Reddit might have a way to let me exclude personal subreddits from search results. I couldn’t find that feature, which left me with one more possible place to put a filter: in the IFTTT applet directly.

And there I struck gold!

Filtering with IFTTT

IFTTT has been around forever in Internet terms. I remember starting to use it around 2012. At that time it was limited to a few online services and a very basic “If this happens, then do that” workflow. Over the years it added a lot more services, but the functionality remained basic.

Eventually IFTTT started expanding how its tools work, and in September 2020 added a Pro plan for users who want to make more extensive, multi-step applets for Internet workflows.  There was some controversy about that and a lot of people were angry about it.

But I’m not. IFTTT Pro is $3.33 a month, which is a bargain considering everything I do with it. I use IFTTT to organize materials I’ve saved to Pocket into a useful Google Sheet. I use it as a quick way to curate Twitter content. It lets me use Newsblur to save items to Pocket. I have even used it to monitor tweets coming from a certain area. Once you’ve got a Pro account, you can make unlimited applets; IFTTT doesn’t try to nickel and dime you if you want to create lots of workflows. I’ve been a paying customer (full freight) since Pro started and I think it’s absolutely worth it.

You will need to have a Pro account to use the solution I’m going to explain in this article. IFTTT offers a 7-day free trial, though, so you can try the steps in the article without giving up any $$$. Who knows, it might give you some useful ideas for more IFTTT tools!

Adding a Filter to an Existing IFTTT Applet

I’ve published an IFTTT applet at https://ifttt.com/applets/HQXFUp4m-monitoring-reddit-for-new-posts-containing-the-keyword-database that you can use to follow along with this article. It periodically searches Reddit for the keyword database and emails any search results. Here’s what it looks like:

If the black and blue slider reads “Connect” instead of “Connected,” you will have to activate the applet. This applet requires that you have IFTTT’s Reddit channel and the email channel activated.

This applet doesn’t yet have a filter. To add one, click on the Settings link in the upper corner. The editing page will look like this:

Click on the + in the middle, where the tool tip reads “Add queries and filter code.” You’ll get the option to either add a filter or add a query.

We’re going to add a filter. Here’s what will happen: every time the applet triggers, the information it gathers will be sent to the filter. The filter will look for /r/u_ , the string common to all the porn spam I’m getting. If it’s found, the subject and content of the mail will get a boilerplate replacement, making it easy to filter such email straight into the trash. Begone, unsolicited tonkers!

But before we get rid of them we have to put the filter in place.

Looking at the Filtering Options

When you choose to Add filter, you’ll get a page with an expected place to put your code, but what’s that stuff underneath? That’s information you get when the IFTTT applet runs, and generally you’ll need to use at least some of it in your filter code. Here’s a quick rundown.

Trigger Data: The Trigger data is what IFTTT gathers from a service when your applet’s “trigger” — the match or event that sets off the IFTTT recipe — is activated. For this applet, IFTTT gathers several different types of data from Reddit:

Reddit.newPostFromSearchReddit.Title

Reddit.newPostFromSearchReddit.ImageURL

Reddit.newPostFromSearchReddit.Content

Reddit.newPostFromSearchReddit.ContentHTML

Reddit.newPostFromSearchReddit.PostURL

Reddit.newPostFromSearchReddit.Subreddit

Reddit.newPostFromSearchReddit.Author

Reddit.newPostFromSearchReddit.PostedAt

What these data are is pretty easy to figure out if you just look at the word after the last period in each item. This IFTTT applet triggers when it finds Reddit posts with a certain keyword and the data are the different elements from a Reddit post: the title, the author, when it was posted, the subreddit, and so on.

What we want is a data element that we can check for a /r/u_ string . You’d think that we could use Reddit.newPostFromSearchReddit.Subreddit for that, wouldn’t you? Well, I tried that and it didn’t work; I think the URL is formatted differently when presented as a subreddit name. The element that I used successfully to find the /r/u_ string is Reddit.newPostFromSearchReddit.PostURL .

User Actions: The user actions are what you can choose to do when your IFTTT applet is triggered. These are a little more obscure but easily understood:

Email.sendMeEmail.skip() – Instead of sending an email with data found using the IFTTT applet like you normally would, you skip it.

Email.sendMeEmail.setSubject() – Send the email as normal only the subject is changed to something you specify.

Email.sendMeEmail.setBody() – Send the email as normal only the body is changed to something you specify.

The easiest thing for me to do would be to create a filter that just skipped sending me Reddit porno spam, using the Email.sendMeEmail.skip() action. But I don’t want to do that for two reasons: 1) It’s not nearly as satisfying as seeing the defused porn spam hit my in-box, and 2) I wanted to see exactly how many spams I was blocking. Instead of just skipping sending an email, therefore, I’m changing both the body and the subject of the message. More about that in a minute.

Other: There are two more elements here called Other that have nothing to do with the applet per se. Instead they’re used if you want to activate applets based on time. We won’t be using them for this article.

Putting in the Filter

IFTTT’s filters are in JavaScript. I’m going to put the whole filter here and then walk you through what it’s doing so you can make your own changes.

(I used to use JavaScript a fair amount but it was fifteen years ago or so and as you might imagine I’m a bit rusty. If my filter’s JavaScript makes you laugh, feel free to give me a couple of hints on how to do it better.)

Paste this entire script into the filter code box:

let str = Reddit.newPostFromSearchReddit.PostURL;

let PornStrings = str.match(/\/r\/u_/);

if (PornStrings) {

  Email.sendMeEmail.setSubject(“Reddit Crap Nobody Asked For”);

  Email.sendMeEmail.setBody(“NOPE”)

}

else {

  Email.sendMeEmail.setSubject(Reddit.newPostFromSearchReddit.Title)

}

Make sure to click the big Update Filter button at the bottom of the box! When you do, you’ll be taken to the main page for the applet. Click on Update to integrate the new filter code into the entire applet.

Now that you’ve made your IFTTT applet, let’s take a look at the filter code line by line:

let str = Reddit.newPostFromSearchReddit.PostURL;

Take the Reddit post URL from the IFTTT applet data and save it to a variable called str.

let PornStrings = str.match(/\/r\/u_/);

In the variable str, we are looking for a match of the string /r/u_ . If we find that match, we’re going to create another variable called PornStrings. If we don’t find that match, the PornStrings variable doesn’t exist.

(Did you notice that the string in the parentheses doesn’t look much like /r/u_ ? It’s because I’m using something called regular expressions to find that string, and in regular expressions / is considered a special character and requires special treatment. Regular expressions is far too huge a subject to tackle here, even briefly, so if you want to learn more let me point you to Syd Johnson’s funny, friendly introduction.)

if (PornStrings) {

Remember, if there’s no match for /r/u_ in the Reddit Post URL, then there’s no variable named PornStrings. All this IF statement is asking is “Does the variable PornStrings exist?” If it does, then the curly bracket starts a list of actions that must be taken. We’re specifying two actions on the next two lines:

Email.sendMeEmail.setSubject(“Reddit Crap Nobody Asked For”);

Email.sendMeEmail.setBody(“NOPE”)

These two lines change the subject of the PornString email to Reddit Crap Nobody Asked For and the body to NOPE, thus removing all those things I didn’t want to look at, yay! Having done that, the list is completed with a closing curly bracket:

}

Ends the actions that must be taken if the IF statement is true.

Underneath the IF statement is the ELSE statement, basically saying “If you didn’t do what was in the IF statement, do this instead.” I’m pretty sure that strictly speaking I don’t need the IF statement; IFTTT will just do what it normally does with the applet and send me an email. But since I’m rusty I’m writing my scripts with training wheels. Here’s the entire ELSE statement, directing the applet to proceed normally and send me an email with the Reddit post title as the subject:

 else {

  Email.sendMeEmail.setSubject(Reddit.newPostFromSearchReddit.Title)

}

A summary in English: you’re telling IFTTT to look at the URL of the Reddit post it just found and see if anything in it matches /r/u_. If it does, IFTTT will change the subject of the email it sends you to “Reddit Crap Nobody Asked For” and the body of the email to “NOPE”. If it doesn’t, IFTTT will send you an email with the contents of the Reddit post and the title of the post as the email’s subject.

Now, do you have to wait around for some spammer to queue up their next load of fecula to test this? Not if you have a Reddit account!

Testing the filter

At the beginning of this article I noted that the string we’re searching for – /r/u_ – matches the formatting for personal subreddits. If you have a Reddit account, check for a personal subreddit at reddit.com/r/u_YOURREDDITNAME . Here’s what mine at

reddit.com/r/u_ResearchBuzz looks like:

All the goofy posts are from me testing the things in this article! I’m going to make yet another one to test the filter we just made.

To post in your personal subreddit, click on the + sign on the top menu bar:

And you’ll get a screen that looks like this:

Make sure it’s set to your personal subreddit before you post!

Put anything you want in the Title spot as long as it includes the word database. That’s what IFTTT needs to find the match with the applet. Put an URL of some sort in the Post part of the form, then move over to the right to the Link tab and enter another URL (It doesn’t matter if they’re the same or different.) Your Reddit applet will not detect your post unless it has a link. Hopefully you do not end up with something this silly:

Now wait for ten minutes or so. Your IFTTT applet will need a few minutes to run. Go get a sandwich or something. Okay, back?

Viewing Your Applet’s Activity Log

Your applets live at https://ifttt.com/home . Look for the one called “Monitoring Reddit for new posts containing the keyword database” and click on it. You’ll get a page that looks like this:

Click on View Activity to see if your post was successfully found. I clicked on the one for my applet and here’s what I found:

If the applet runs and doesn’t find anything, you won’t get a notification. But if does run and it does find something, you’ll get a notification that looks like the above. IFTTT first shows me when the applet ran and the Reddit post that triggered it. You can then expand the Reddit sections to see what data IFTTT gathered when the applet was triggered:

(Hmm, looking at that now I know why searching the Subreddit string for /r/u_ didn’t work.)

Finally, IFTTT shows what actions were taken by the applet:

Please be careful when you expand the Email section. IFTTT will change the body and subject of the email that’s sent to you, but the original body and title are preserved here in the activity log, and if your applet is working correctly it’s pretty pornish stuff.

(Sometimes you might get a big APPLET FAILED message in your activity log. In my experience that’s when IFTTT fails to run a search or execute an action. It probably doesn’t have anything to do with your script unless you’re getting actual script errors. If it is IFTTT’s issue, give it ten minutes or so; IFTTT will rerun the applet. It’s usually successful the second time.)

The Results After a About a Week

Where are we now? We have an IFTTT search of Reddit that filters out pornography spam, giving it a standard title and body. That means the posts thread in my GMail instead of being scattered around my in-box. I successfully activated this applet for another search (my Reddit search for archive) on November 7th. Under a week later here’s the count of filtered Reddit porn spams:

In about six days my IFTTT stopped five hundred and seven porn spams from cluttering up my in-box. It’s a lot! (Do you see why I found them so annoying?)

And did it catch all of the Reddit porn spam? Yes. Apparently the personal subreddits are the only way this content is spread (for the moment.) There is a minuscule chance I will miss a posted resource that someone posts about only in their own subreddit, but I’m not concerned. This strong filter is far more important to me.

I’m so pleased with how well adding a filter to an IFTTT applet worked that I want to try it with other things. If you’ve got any ideas, chuck ’em in the comments. Or if you’re feeling inspired yourself, check out these resources from IFTTT:

Building with Filter Code – https://help.ifttt.com/hc/en-us/articles/360052451954-Building-with-filter-code 

An overview of using IFTTT filter code, with examples. Might be a little too much for beginners; if you found my JavaScript explanations tedious you’ll like this much better.

Example Apples with query and filter code – https://help.ifttt.com/hc/en-us/articles/360053657913-Example-Applets-using-queries-and-filter-code

Some more advanced filters, with examples that might light up your imagination. 

Filter Code Generators – https://help.ifttt.com/hc/en-us/articles/1260805596369-Filter-code-generators

This will help you generate JavaScript to put in your filters. You’ll notice that the last generator, which generates JavaScript looking for keywords, looks a lot different from mine. 😂

Filter Code Samples – https://help.ifttt.com/hc/en-us/sections/4406000988827-Filter-code-samples

A small group of articles providing filter codes for specific situations (like “Can I make my Applet only run on weekdays (or weekends)?” and “How can I run an Applet only after sunset?”)

Categories: Learning Search, Rants

Tagged as: , ,

Leave a Reply