1. Home
  2. E-mail: Advanced
  3. Search Queries and Dovecot Queries

Search Queries and Dovecot Queries

Search Queries and Dovecot Queries

When managing your email accounts, on several occasions you may require a specific Search Query. These are also known as Doveadm commands. This guide should give you a brief overview of the Dove commands you can use.

Several queries use a search_query in order to act on only matching emails.  Each search_query should consist of at least one Search Key which will require an argument prior. As a rule, all Search Keys are Case insensitive. An example of a Search key would be ‘ALL’ in the following:

doveamd search ALL

This search_query would search all the available messages.

List of Search Keys and Uses
ALL

Matches all messages.

ANSWERED

Matches all messages with the IMAP flag \Answered set.

BCC string

Matches all messages which contain ‘string’in the BCC field of the message’s IMAP envelope structure.

BEFORE Date Specification

Matches all the messages with an internal date before ‘Date Specification’.

BODY String

Matches all the messages that contain ‘String’in the body section.

CC String

Matches all messages which contain ‘String’in the CC field in the message’s IMAP envelope structure.

DELETED

Matches messages with the IMAP flag \Deleted set.

Draft

Matches messages with the IMAP flag \Draft set.

FLAGGED

Matches messages with the IMAP flag \Flagged set.

FROM String

Matches messages which contain ‘String’ in the FROM field of the message’s IMAP envelope structure.

HEADER Field String

Matches messages, which either have the named header ‘Field’, when empty ‘String’ was given. Or messages, where the given header ‘Field’ value contains the specified string.

KEYWORD Keyword

Matches messages with the given IMAP keyword (e.g. $Forwarded) flag set.

LARGER Size

Matches messages that are larger than the specified size’.

MAILBOX Name

Matches messages in the mailbox with the specified ‘Name’.

MAILBOX-GUID Guid

Matches messages in the mailbox with the specified ‘Guid’.

NEW

Matches messages, which have the IMAP flag \Recent set but not the IMAP flag \Seen.

NOT Search Key

Inverse matching – matches massages, where the search doesn’t match the specified ‘Search Key’ or its value.

OLD

Matches messages, which do not have the IMAP flag \Recent set.

ON Specific Date

Matches messages whose internal date matches the given ‘Specific Date’.

Search Key OR Search Key

Matches messages where one of the OR ‘Search Key’ s matches. But not if both match.

RECENT

Matches messages with the IMAP flag \Recent set.

SEEN

Matches messages with the IMAP flag \Seen set.

SENTBEFORE Specific Date

Matches messages with a Date: header before ‘Specific Date’.

SENTON Specific Date

Matches messages with a Date: header matching the given ‘Specific Date’.

SENTSINCE Specific Date

Matches messages with a Date: header matching or after the given Specific Date’.

SINCE Specific Date

Matches messages whose internal date is within or after the given ‘Specific Date’.

SMALLER Size

Matches messages with a size smaller than the given ‘Size’.

SUBJECT String

Matches messages, which contain ‘String’ in the SUBJECT field of the message’s IMAP envelope structure.

Text String

Matches messages, which contain ‘String’ in the message body.

TO String

Matches messages, which contain ‘String’ in the TO field of the message’s IMAP envelope structure.

UID Sequence

Matches messages with the given UID(s). A sequence may be a single UID. Can be a sequence range, written as from:to, e.g. 100:125. As comma separated list of UIDs, e.g. 11,50,4. It’s also possible to combine multiple sequences, e.g. 1,3,5,7,10:20.

UNANSWERED

Matches messages, which do not have the IMAP flag \Answered set.

UNDELETED

Matches messages, which do not have the IMAP flag \Deleted set.

UNDRAFT

Matches messages, which do not have the IMAP flag \Draft set.

UNFLAGGED

Matches messages, which do not have the IMAP flag \Flagged set.

UNKEYWORD Keyword

Matches messages, which do not have the given IMAP ‘Keyword’ flag set.

UNSEEN

Matches messages, which do not have the IMAP flag \Seen set.

SAVEDBEFORE Specific Date

Matches messages, which were saved before ‘Specific Date’.

SAVEDON Specific Date

Matches messages whose save date matches the given ‘Specific Date’.

SAVEDSINCE Specific Date

Matches messages with a save date matching or after the given ‘Specific Date’.

FROM email address

Matches all messages from ’email address’. Through using this command on our control panel you can use this command to delete mail from a specific address, we have found this is good for removing virus mail or chain mail.

Date Specification

When writing ‘Specific Date’ after Search Queries, a certain format must be followed to do so correctly. These formats include:

Day-Month-Year

Where ‘Day’ is the day of the month: 1 – 31.

Where ‘Month’ is the month abbreviated name: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec

Where ‘Year’is the year using four digits. E.g ‘2017’

Interval

Where the time units include: w or weeks for weeks, d or days for days, h or hours for hours, m or mins for minutes, s or secs for seconds.

To match messages from last week, you may specify for example: since 1wsince 1weeks or since 7days.

Unix Timestamp

A 10 digit Unix timestamp, seconds since the 1st of January 1970, 00:00:00 UTC. For example the “13th of April 2007” will be represented as 1176418800.

YY-MM-DD

Extended ISO-8601 calendar date format. For example the “13th of April 2007” will be represented as 2007-04-13.

Sizing

Where ‘Size’ is a specific format that can be used within search queries.

Octets

The message size in octets, as specified in the IMAP4rev1 specification.

Size

The message size in B (byte), K (kilobyte), M (megabyte), G (gigabyte) or T (terabyte).
To match messages, bigger than 1 megabyte, you may specify for example: larger 1M or larger 1024K.

Updated on 12th November 2018

Was this article helpful?

Related Articles