NeoMutt  2024-03-23-142-g2b2e76
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
private.h File Reference

Shared constants/structs that are private to libpattern. More...

#include <stdbool.h>
#include "mutt/lib.h"
#include "email/lib.h"
#include "lib.h"
+ Include dependency graph for private.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PatternEntry
 A line in the Pattern Completion menu. More...
 
struct  PatternFlags
 Mapping between user character and internal constant. More...
 
struct  RangeRegex
 Regular expression representing a range. More...
 

Macros

#define RANGE_NUM_RX   "([[:digit:]]+|0x[[:xdigit:]]+)[MmKk]?"
 
#define RANGE_REL_SLOT_RX   "[[:blank:]]*([.^$]|-?" RANGE_NUM_RX ")?[[:blank:]]*"
 
#define RANGE_REL_RX   "^" RANGE_REL_SLOT_RX "," RANGE_REL_SLOT_RX
 
#define RANGE_ABS_SLOT_RX   "[[:blank:]]*([.^$]|" RANGE_NUM_RX ")?[[:blank:]]*"
 
#define RANGE_ABS_RX   "^" RANGE_ABS_SLOT_RX "-" RANGE_ABS_SLOT_RX
 
#define RANGE_LT_RX   "^()[[:blank:]]*(<[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"
 
#define RANGE_GT_RX   "^()[[:blank:]]*(>[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"
 
#define RANGE_BARE_RX   "^[[:blank:]]*([.^$]|" RANGE_NUM_RX ")[[:blank:]]*"
 
#define RANGE_RX_GROUPS   5
 
#define RANGE_DOT   '.'
 
#define RANGE_CIRCUM   '^'
 
#define RANGE_DOLLAR   '$'
 
#define RANGE_LT   '<'
 
#define RANGE_GT   '>'
 
#define MUTT_MAXRANGE   -1
 

Enumerations

enum  ExpandoDataPattern { ED_PAT_DESCRIPTION = 1 , ED_PAT_EXPRESION , ED_PAT_NUMBER }
 Expando UIDs for Patterns. More...
 
enum  PatternEat {
  EAT_NONE , EAT_REGEX , EAT_DATE , EAT_RANGE ,
  EAT_MESSAGE_RANGE , EAT_QUERY
}
 Function to process pattern arguments. More...
 
enum  RangeType {
  RANGE_K_REL , RANGE_K_ABS , RANGE_K_LT , RANGE_K_GT ,
  RANGE_K_BARE , RANGE_K_INVALID
}
 Type of range. More...
 
enum  RangeSide { RANGE_S_LEFT , RANGE_S_RIGHT }
 Which side of the range. More...
 

Functions

static int email_msgno (struct Email *e)
 Helper to get the Email's message number.
 
const struct PatternFlagslookup_op (int op)
 Lookup the Pattern Flags for an op.
 
const struct PatternFlagslookup_tag (char tag)
 Lookup a pattern modifier.
 
bool eval_date_minmax (struct Pattern *pat, const char *s, struct Buffer *err)
 Evaluate a date-range pattern against 'now'.
 
bool eat_message_range (struct Pattern *pat, PatternCompFlags flags, struct Buffer *s, struct Buffer *err, struct MailboxView *mv)
 Parse a range of message numbers - Implements eat_arg_t -.
 

Variables

struct RangeRegex RangeRegexes []
 Set of Regexes for various range types.
 
const struct PatternFlags Flags []
 Lookup table for all patterns.
 

Detailed Description

Shared constants/structs that are private to libpattern.

Authors
  • Richard Russon

This program 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 this program. If not, see http://www.gnu.org/licenses/.

Definition in file private.h.

Macro Definition Documentation

◆ RANGE_NUM_RX

#define RANGE_NUM_RX   "([[:digit:]]+|0x[[:xdigit:]]+)[MmKk]?"

Definition at line 111 of file private.h.

◆ RANGE_REL_SLOT_RX

#define RANGE_REL_SLOT_RX   "[[:blank:]]*([.^$]|-?" RANGE_NUM_RX ")?[[:blank:]]*"

Definition at line 112 of file private.h.

◆ RANGE_REL_RX

#define RANGE_REL_RX   "^" RANGE_REL_SLOT_RX "," RANGE_REL_SLOT_RX

Definition at line 113 of file private.h.

◆ RANGE_ABS_SLOT_RX

#define RANGE_ABS_SLOT_RX   "[[:blank:]]*([.^$]|" RANGE_NUM_RX ")?[[:blank:]]*"

Definition at line 116 of file private.h.

◆ RANGE_ABS_RX

#define RANGE_ABS_RX   "^" RANGE_ABS_SLOT_RX "-" RANGE_ABS_SLOT_RX

Definition at line 117 of file private.h.

◆ RANGE_LT_RX

#define RANGE_LT_RX   "^()[[:blank:]]*(<[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"

Definition at line 120 of file private.h.

◆ RANGE_GT_RX

#define RANGE_GT_RX   "^()[[:blank:]]*(>[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"

Definition at line 121 of file private.h.

◆ RANGE_BARE_RX

#define RANGE_BARE_RX   "^[[:blank:]]*([.^$]|" RANGE_NUM_RX ")[[:blank:]]*"

Definition at line 124 of file private.h.

◆ RANGE_RX_GROUPS

#define RANGE_RX_GROUPS   5

Definition at line 125 of file private.h.

◆ RANGE_DOT

#define RANGE_DOT   '.'

Definition at line 127 of file private.h.

◆ RANGE_CIRCUM

#define RANGE_CIRCUM   '^'

Definition at line 128 of file private.h.

◆ RANGE_DOLLAR

#define RANGE_DOLLAR   '$'

Definition at line 129 of file private.h.

◆ RANGE_LT

#define RANGE_LT   '<'

Definition at line 130 of file private.h.

◆ RANGE_GT

#define RANGE_GT   '>'

Definition at line 131 of file private.h.

◆ MUTT_MAXRANGE

#define MUTT_MAXRANGE   -1

Definition at line 152 of file private.h.

Enumeration Type Documentation

◆ ExpandoDataPattern

Expando UIDs for Patterns.

See also
ED_PATTERN, ExpandoDomain
Enumerator
ED_PAT_DESCRIPTION 

PatternEntry.desc.

ED_PAT_EXPRESION 

PatternEntry.expr.

ED_PAT_NUMBER 

PatternEntry.num.

Definition at line 49 of file private.h.

50{
54};
@ ED_PAT_DESCRIPTION
PatternEntry.desc.
Definition: private.h:51
@ ED_PAT_EXPRESION
PatternEntry.expr.
Definition: private.h:52
@ ED_PAT_NUMBER
PatternEntry.num.
Definition: private.h:53

◆ PatternEat

enum PatternEat

Function to process pattern arguments.

Values for PatternFlags.eat_arg

Enumerator
EAT_NONE 

No arguments required.

EAT_REGEX 

Process a regex.

EAT_DATE 

Process a date (range)

EAT_RANGE 

Process a number (range)

EAT_MESSAGE_RANGE 

Process a message number (range)

EAT_QUERY 

Process a query string.

Definition at line 61 of file private.h.

62{
63 EAT_NONE,
64 EAT_REGEX,
65 EAT_DATE,
66 EAT_RANGE,
68 EAT_QUERY,
69};
@ EAT_NONE
No arguments required.
Definition: private.h:63
@ EAT_RANGE
Process a number (range)
Definition: private.h:66
@ EAT_MESSAGE_RANGE
Process a message number (range)
Definition: private.h:67
@ EAT_DATE
Process a date (range)
Definition: private.h:65
@ EAT_QUERY
Process a query string.
Definition: private.h:68
@ EAT_REGEX
Process a regex.
Definition: private.h:64

◆ RangeType

enum RangeType

Type of range.

Enumerator
RANGE_K_REL 

Relative range.

RANGE_K_ABS 

Absolute range.

RANGE_K_LT 

Less-than range.

RANGE_K_GT 

Greater-than range.

RANGE_K_BARE 

Single symbol.

RANGE_K_INVALID 

Range is invalid.

Definition at line 99 of file private.h.

100{
103 RANGE_K_LT,
104 RANGE_K_GT,
106 /* add new ones HERE */
108};
@ RANGE_K_REL
Relative range.
Definition: private.h:101
@ RANGE_K_ABS
Absolute range.
Definition: private.h:102
@ RANGE_K_LT
Less-than range.
Definition: private.h:103
@ RANGE_K_INVALID
Range is invalid.
Definition: private.h:107
@ RANGE_K_BARE
Single symbol.
Definition: private.h:105
@ RANGE_K_GT
Greater-than range.
Definition: private.h:104

◆ RangeSide

enum RangeSide

Which side of the range.

Enumerator
RANGE_S_LEFT 

Left side of range.

RANGE_S_RIGHT 

Right side of range.

Definition at line 136 of file private.h.

137{
140};
@ RANGE_S_LEFT
Left side of range.
Definition: private.h:138
@ RANGE_S_RIGHT
Right side of range.
Definition: private.h:139

Function Documentation

◆ email_msgno()

static int email_msgno ( struct Email e)
inlinestatic

Helper to get the Email's message number.

Parameters
eEmail
Return values
numMessage number

Definition at line 147 of file private.h.

148{
149 return e->msgno + 1;
150}
int msgno
Number displayed to the user.
Definition: email.h:114
+ Here is the caller graph for this function:

◆ lookup_op()

const struct PatternFlags * lookup_op ( int  op)

Lookup the Pattern Flags for an op.

Parameters
opOperation, e.g. MUTT_PAT_SENDER
Return values
ptrPatternFlags

Definition at line 211 of file flags.c.

212{
213 for (int i = 0; Flags[i].tag; i++)
214 if (Flags[i].op == op)
215 return (&Flags[i]);
216 return NULL;
217}
const struct PatternFlags Flags[]
Lookup table for all patterns.
Definition: flags.c:40
int tag
Character used to represent this operation, e.g. 'A' for '~A'.
Definition: private.h:76
+ Here is the caller graph for this function:

◆ lookup_tag()

const struct PatternFlags * lookup_tag ( char  tag)

Lookup a pattern modifier.

Parameters
tagLetter, e.g. 'b' for pattern '~b'
Return values
ptrPattern data

Definition at line 198 of file flags.c.

199{
200 for (int i = 0; Flags[i].tag; i++)
201 if (Flags[i].tag == tag)
202 return &Flags[i];
203 return NULL;
204}
+ Here is the caller graph for this function:

◆ eval_date_minmax()

bool eval_date_minmax ( struct Pattern pat,
const char *  s,
struct Buffer err 
)

Evaluate a date-range pattern against 'now'.

Parameters
patPattern to modify
sPattern string to use
errBuffer for error messages
Return values
truePattern valid and updated
falsePattern invalid

Definition at line 495 of file compile.c.

496{
497 /* the '0' time is Jan 1, 1970 UTC, so in order to prevent a negative time
498 * when doing timezone conversion, we use Jan 2, 1970 UTC as the base here */
499 struct tm min = { 0 };
500 min.tm_mday = 2;
501 min.tm_year = 70;
502
503 /* Arbitrary year in the future. Don't set this too high or
504 * mutt_date_make_time() returns something larger than will fit in a time_t
505 * on some systems */
506 struct tm max = { 0 };
507 max.tm_year = 130;
508 max.tm_mon = 11;
509 max.tm_mday = 31;
510 max.tm_hour = 23;
511 max.tm_min = 59;
512 max.tm_sec = 59;
513
514 if (strchr("<>=", s[0]))
515 {
516 /* offset from current time
517 * <3d less than three days ago
518 * >3d more than three days ago
519 * =3d exactly three days ago */
520 struct tm *tm = NULL;
521 bool exact = false;
522
523 if (s[0] == '<')
524 {
526 tm = &min;
527 }
528 else
529 {
531 tm = &max;
532
533 if (s[0] == '=')
534 exact = true;
535 }
536
537 /* Reset the HMS unless we are relative matching using one of those
538 * offsets. */
539 char *offset_type = NULL;
540 strtol(s + 1, &offset_type, 0);
541 if (!(*offset_type && strchr("HMS", *offset_type)))
542 {
543 tm->tm_hour = 23;
544 tm->tm_min = 59;
545 tm->tm_sec = 59;
546 }
547
548 /* force negative offset */
549 get_offset(tm, s + 1, -1);
550
551 if (exact)
552 {
553 /* start at the beginning of the day in question */
554 memcpy(&min, &max, sizeof(max));
555 min.tm_hour = 0;
556 min.tm_sec = 0;
557 min.tm_min = 0;
558 }
559 }
560 else
561 {
562 const char *pc = s;
563
564 bool have_min = false;
565 bool until_now = false;
566 if (isdigit((unsigned char) *pc))
567 {
568 /* minimum date specified */
569 pc = get_date(pc, &min, err);
570 if (!pc)
571 {
572 return false;
573 }
574 have_min = true;
575 SKIPWS(pc);
576 if (*pc == '-')
577 {
578 const char *pt = pc + 1;
579 SKIPWS(pt);
580 until_now = (*pt == '\0');
581 }
582 }
583
584 if (!until_now)
585 { /* max date or relative range/window */
586
587 struct tm base_min = { 0 };
588
589 if (!have_min)
590 { /* save base minimum and set current date, e.g. for "-3d+1d" */
591 memcpy(&base_min, &min, sizeof(base_min));
593 min.tm_hour = 0;
594 min.tm_sec = 0;
595 min.tm_min = 0;
596 }
597
598 /* preset max date for relative offsets,
599 * if nothing follows we search for messages on a specific day */
600 max.tm_year = min.tm_year;
601 max.tm_mon = min.tm_mon;
602 max.tm_mday = min.tm_mday;
603
604 if (!parse_date_range(pc, &min, &max, have_min, &base_min, err))
605 { /* bail out on any parsing error */
606 return false;
607 }
608 }
609 }
610
611 /* Since we allow two dates to be specified we'll have to adjust that. */
612 adjust_date_range(&min, &max);
613
614 pat->min = mutt_date_make_time(&min, true);
615 pat->max = mutt_date_make_time(&max, true);
616
617 return true;
618}
static const char * parse_date_range(const char *pc, struct tm *min, struct tm *max, bool have_min, struct tm *base_min, struct Buffer *err)
Parse a date range.
Definition: compile.c:363
static void adjust_date_range(struct tm *min, struct tm *max)
Put a date range in the correct order.
Definition: compile.c:457
static const char * get_offset(struct tm *tm, const char *s, int sign)
Calculate a symbolic offset.
Definition: compile.c:223
static const char * get_date(const char *s, struct tm *t, struct Buffer *err)
Parse a (partial) date in dd/mm/yyyy format.
Definition: compile.c:277
struct tm mutt_date_localtime(time_t t)
Converts calendar time to a broken-down time structure expressed in user timezone.
Definition: date.c:905
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
Definition: date.c:241
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:455
#define SKIPWS(ch)
Definition: string2.h:45
long min
Minimum for range checks.
Definition: lib.h:88
long max
Maximum for range checks.
Definition: lib.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ RangeRegexes

struct RangeRegex RangeRegexes[]
extern

Set of Regexes for various range types.

This array, will also contain the compiled regexes.

Definition at line 65 of file pattern.c.

◆ Flags

const struct PatternFlags Flags[]
extern

Lookup table for all patterns.

Definition at line 40 of file flags.c.