search.exp 5.76 KB
# -*- tcl -*-
# This file is part of Mailutils testsuite.
# Copyright (C) 2002, 2007, 2010, 2011 Free Software Foundation, Inc.
#  
# GNU Mailutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#   
# GNU Mailutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 

# 6.4.4.  SEARCH Command
# Arguments:  OPTIONAL [CHARSET] specification
#             searching criteria (one or more)
# Responses:  REQUIRED untagged response: SEARCH
# Result:     OK - search completed
#             NO - search error: can't search that [CHARSET] or
#             criteria
#             BAD - command unknown or arguments invalid
#
#      The SEARCH command searches the mailbox for messages that match
#      the given searching criteria.  Searching criteria consist of one
#      or more search keys.  The untagged SEARCH response from the server
#      contains a listing of message sequence numbers corresponding to
#      those messages that match the searching criteria.

imap4d_start -mbox "search.mbox"
imap4d_auth "user!passwd" "guessme"

imap4d_test "SELECT INBOX"\
"8 EXISTS"\
"5 RECENT"\
-re {OK \[UIDVALIDITY [0-9]+\] UID valididy status}\
"OK \[UIDNEXT 9\] Predicted next uid"\
"OK \[UNSEEN 4\] first unseen messsage "\
"FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)"\
"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags"\
"OK \[READ-WRITE\] SELECT Completed"

# <message set>  Messages with message sequence numbers
#                corresponding to the specified message sequence
#                number set

imap4d_test "SEARCH 1:*" \
"SEARCH 1 2 3 4 5 6 7 8" \
"OK"

# ALL            All messages in the mailbox; the default initial
#                key for ANDing.

imap4d_test "SEARCH ALL" \
"SEARCH 1 2 3 4 5 6 7 8" \
"OK"

# NEW            Messages that have the \Recent flag set but not the
#                \Seen flag.  This is functionally equivalent to
#                "(RECENT UNSEEN)".

# All messages are still new
imap4d_test "SEARCH NEW" \
"SEARCH 4 5 6 7 8" \
"OK"

# FROM <string>  Messages that contain the specified string in the
#                envelope structure's FROM field.

imap4d_test "SEARCH FROM corrector" \
"SEARCH 2 4 8" \
"OK"

imap4d_test "SEARCH FROM lexi@example.net" \
"SEARCH 1 3 5 6 7" \
"OK"

# LARGER <n>     Messages with an [RFC-822] size larger than the
#                specified number of octets.

imap4d_test "SEARCH LARGER 512" \
"SEARCH 3 4" \
"OK"

# SMALLER <n>    Messages with an [RFC-822] size smaller than the
#                specified number of octets.

imap4d_test "SEARCH SMALLER 400" \
"SEARCH 7 8" \
"OK"

# SUBJECT <string>   Messages that contain the specified string in the
#                    envelope structure's SUBJECT field.

imap4d_test "SEARCH SUBJECT \"Alliance\"" \
"SEARCH 6"\
"OK"

# HEADER <field-name> <string>
#                    Messages that have a header with the specified
#                    field-name (as defined in [RFC-822]) and that
#                    contains the specified string in the [RFC-822]
#                    field-body.

imap4d_test "SEARCH HEADER Message-Id \"<200207291200.3303@example.org>\"" \
"SEARCH 3" \
"OK"	

# CC <string>    Messages that contain the specified string in the
#                 envelope structure's CC field.

imap4d_test "SEARCH CC Corrector" \
"SEARCH 6" \
"OK"

# TO <string>    Messages that contain the specified string in the
#                envelope structure's TO field.

imap4d_test "SEARCH TO editor+recheck"\
"SEARCH 7" \
"OK"

# SENTBEFORE <date>
#                Messages whose [RFC-822] Date: header is earlier
#                than the specified date.

imap4d_test "SEARCH SENTBEFORE \"30-Jul-2002\"" \
"SEARCH 1 2"\
"OK"

# SENTSINCE <date>
#                Messages whose [RFC-822] Date: header is within or
#                later than the specified date.

imap4d_test "SEARCH SENTSINCE \"31-Jul-2002\""\
"SEARCH 5 6 7 8"\
"OK"

# BEFORE <date>  Messages whose internal date is earlier than the
#                specified date.

imap4d_test "SEARCH BEFORE \"30-Jul-2002\""\
"SEARCH 1"\
"OK"

# SINCE <date>   Messages whose internal date is within or later
#                than the specified date.

imap4d_test "SEARCH SINCE \"30-Jul-2002\""\
"SEARCH 2 3 4 5 6 7 8"\
"OK"

# ANSWERED       Messages with the \Answered flag set.

imap4d_test "SEARCH ANSWERED"\
"SEARCH 2 3"\
"OK"

# TEXT <string>  Messages that contain the specified string in the
#                header or body of the message.

imap4d_test "SEARCH TEXT person"\
"SEARCH 2 5 8"\
"OK"

## Boolean operations

# When multiple keys are specified, the result is the intersection
# (AND function) of all the messages that match those keys.

imap4d_test "SEARCH TEXT person FROM corrector"\
"SEARCH 2"\
"OK"

imap4d_test "SEARCH SENTSINCE \"30-Jul-2002\" SENTBEFORE \"31-Jul-2002\"" \
"SEARCH 3 4" \
"OK"    

# OR <search-key1> <search-key2>
#                Messages that match either search key.

imap4d_test "SEARCH OR FROM corrector ANSWERED"\
"SEARCH 2 3 4 8" \
"OK"    

## Check precedence

imap4d_test "SEARCH (OR FROM corrector ANSWERED) SENTSINCE \"30-Jul-2002\""\
"SEARCH 3 4 8" \
"OK"

imap4d_test "SEARCH OR FROM corrector ANSWERED SENTSINCE \"30-Jul-2002\""\
"SEARCH 3 4 8" \
"OK"

imap4d_test "SEARCH OR FROM corrector (ANSWERED SENTSINCE \"30-Jul-2002\")"\
"SEARCH 2 3 4 8" \
"OK"

imap4d_stop

# End of search.exp