Mailflag for Android
Mailflag

Nederlands
is a notification service for IMAP IDLE, featuring advanced
configurable From, Subject, To/Cc and Body content filters
and may serve as spam filter for your email app.


THIS APP HAS PRE-OREO FUNCTIONALITY AND IS THEREFORE NOT AVAILABLE IN GOOGLE PLAY STORE. The app can be downloaded here (manual installation using a file manager). Version 8.3 (March 2021) for Android 4.1+


Purpose

Many Android email apps are lacking proper filtering capabilities, leading to unwanted new mail notifications.
Mailflag is designed to be a front end for such applications, in that it provides filtered notifications only, launching the email app if desired. You can disable notification from the email app itself and let it download headers only, effectively resulting in an email app with advanced spam filtering. Mailflag does not interfere with the email app in any way.


Description

Mailflag is a tool, meant to run in the background, with a light footprint, and as invisible as possible.
The user interface is kept simple, yet providing all basic functionality. It will run with a scaling layout on Android version 4.1 and higher, on smartphone and tablet.
Mailflag main screen
Mailflag has five different modes of operation:


In the first three (idling) modes, a poll is performed after connection loss.
If your device allows it to keep notifying when the screen is off, Foreground Service is the preferred choice. If not, switch to Polling Mode.
In polling state, the button 'Start service' becomes 'Poll now' and will broadcast an external intent and hence perform an additional check for new mail.
Polling flags all messages to prevent repeated notification.
You may need to check the Wi-Fi Sleep Policy setting of your device.

With Android 6.0+ the app will ask once for exclusion from Battery Optimization ('Doze mode').
With Android 8.0+ each service must run in foreground, but the permanent icon can be disabled.

Configurable filters limit notifications to specific (groups of) sender and to/cc addresses, subject and body content.
Each filter may contain multiple ||-separated strings. A string within slashes is evaluated as regular expression. See the explained filter examples below.
Notification sound, LED color, and many others, are configurable using the Options menu.
The new email notification can launch any non-system app with a (package) name containing 'mail'.
The notification shows 'Mailflag:' in its title, which allows detection by e.g. Tasker (%NTITLE variable).

Mailflag can add a custom prefix to the subject of rejected (not notified) mail.
Email clients that provide basic filtering (such as 'Email Spam Blocker' from Maxlab) can use this prefix to move the mail to a different folder.
Note: adding a prefix is not possible on gmail servers.

The current version supports a single connection using imaps (strict/any) for SSL, imap for NON-SSL.
Backup/Restore does allow easy switching between different accounts (see below).

Mailflag will run with a trial limitation until a license is purchased (in-app purchase). The application is fully functional, but the service stops after 72 hours. The license removes this limitation.

PLEASE RUN MAILFLAG IN TRIAL MODE FIRST, TO VERIFY THAT IT RUNS ON YOUR DEVICE AND MEETS YOUR EXPECTATIONS.


Usage

Mailflag has settings and options.
Settings provide connection and filter settings, and are reached by pressing the 'Settings' button.
Options are reached using the Android menu button, these contain less frequently changed configuration.
Most settings/options are self-explanatory, some are discussed in more detail below.

Note: if yoy want to connect to imap.gmail.com, you will need to enable 'Less secure app access' in the Google account settings.

Mailflag settings
SETTINGS

Port
the standard port is 993 for imaps (SSL), or 143 for imap (NON-SSL).

Filters may contain multiple ||-separated strings.
All filters except regular expressions are case-insensitive. Empty filters pass all.
Empty fillters take no processing power, non-empty body content filters the most.

From contains: new mail is checked for presence of at least one of the defined strings in the address.

The Subject, To/Cc and Body filters work in the same way.

See the explained filter examples below.

Mailflag options
OPTIONS

Enable vibration
The default notification vibration pattern is used.


Repeat
On selection, separate options for repeated notification appear.


Pause at night
On selection, time pickers appear to set begin and end time. Service or polling is paused during this period.

Notify once
After notification, further notifications are suppressed until the first notification is acknowledged.
Note: deleting email from the server removes the notification as well.

Sound
Mailflag will scan all notification sounds that are available on your device. These are available for selection.

Launch app
Mailflag will scan all installed apps with a package name that contains 'mail'. These are available for selection (as well as Gmail).

Mailflag backup/restore
BACKUP and RESTORE


Settings and options can be saved to and restored from the device's default primary external storage location (SD card).
By giving each backup an account-specific name, Restore allows easy switching between different accounts.
Backup and Restore are reached using the Android menu button.









Filter examples (explained)

From contains:   /(\.uk|@(gmail|hotmail|outlook)\.com)[>)]?$/

This is a regular expression that (in the UK) will filter most spam.
Mailflag will notify only mail from UK-based domains, plus mail from gmail.com, hotmail.com and outlook.com.
The character sequence [>)]?$ means that the match must be at the end of the address, optionally with a > or ).
The expression can easily be extended. Suppose you want to include mail from prima.eu, than we get:

From contains:   /(\.uk|prima\.eu|@(gmail|hotmail|outlook)\.com)[>)]?$/

| means 'or'. The . in a regular expression must be escaped because otherwise it stands for any character.

When UK-based spammers must be excluded, use 'From not contains':

From not contains:   company1.co.uk || company2.co.uk

This is not a regular expression, but the combination of two strings. If company1 is a rare name, 'company1' instead of 'company1.co.uk' would be sufficient. || means 'or' here. In ordinary strings the . is not escaped.

It's possible to combine regular expressions and strings, as in:

Subject not contains:   /\*+SPAM\*+/ || viagra

***SPAM*** is the default SpamAssassin prefix. Strings as 'viagra' are evaluated case-insensitive.
(In this case, however, a string ***SPAM*** takes less processing power than the regular expression.)


Privacy statement

Mailflag will only ask permissions that are necessary for fulfilling the task indicated in its description.
No data is collected other than necessary for fulfilling this task, and no data is in any way transmitted from/to your device or from/to another application.

© Bryk NL 2019
Egbert Boerma



See also: ReAlert all-in-1 notification app