summaryrefslogtreecommitdiff
path: root/include/mailutils/msgset.h
blob: 4e467db43b6824ebdefff3e15bd33693ea5b3320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* GNU Mailutils -- a suite of utilities for electronic mail
   Copyright (C) 2011-2020 Free Software Foundation, Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library 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
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library.  If not, see
   <http://www.gnu.org/licenses/>. */

#ifndef _MAILUTILS_MSGSET_H
#define _MAILUTILS_MSGSET_H

# include <mailutils/types.h>
  
#ifdef __cplusplus
extern "C" {
#endif

struct mu_msgrange
{
  size_t msg_beg;
  size_t msg_end;
};

struct mu_msgset_format
{
  char *range;   /* range separator (e.g., ":" for IMAP, "-" for MH) */
  char *delim;   /* delimiter       (e.g., "," for IMAP, " " for MH) */
  char *last;    /* last message marker (e.g., "*" for IMAP, "last" for MH) */
  char *empty;   /* empty list representation ( "NIL", for IMAP, NULL for MH */
};

enum
  {
    MU_MSGSET_FMT_IMAP,
    MU_MSGSET_FMT_MH
  };

extern struct mu_msgset_format const mu_msgset_formats[];
typedef struct mu_msgset_format const *mu_msgset_format_t;
#define mu_msgset_fmt_imap (&mu_msgset_formats[MU_MSGSET_FMT_IMAP])
#define mu_msgset_fmt_mh   (&mu_msgset_formats[MU_MSGSET_FMT_MH])
  
/* Message numbers start with 1.  MU_MSGNO_LAST denotes the last
   message. */
#define MU_MSGNO_LAST   0

#define MU_MSGSET_NUM   0      /* Message set operates on sequence numbers */
#define MU_MSGSET_UID   1      /* Message set operates on UIDs */

#define MU_MSGSET_IGNORE_TRANSERR 0x10
  
#define MU_MSGSET_MODE_MASK 0x0f
  
int mu_msgset_create (mu_msgset_t *pmsgset, mu_mailbox_t mbox, int mode);

int mu_msgset_copy (mu_msgset_t src, mu_msgset_t dst);
int mu_msgset_translate (mu_msgset_t *dst, mu_msgset_t src, int flags);
  
int mu_msgset_get_list (mu_msgset_t msgset, mu_list_t *plist);
int mu_msgset_get_iterator (mu_msgset_t msgset, mu_iterator_t *pitr);

int mu_msgset_sget_mailbox (mu_msgset_t mset, mu_mailbox_t *mbox);
  
int mu_msgset_add_range (mu_msgset_t set, size_t beg, size_t end, int mode);
int mu_msgset_sub_range (mu_msgset_t set, size_t beg, size_t end, int mode);
int mu_msgset_add (mu_msgset_t a, mu_msgset_t b);
int mu_msgset_sub (mu_msgset_t a, mu_msgset_t b);
int mu_msgset_aggregate (mu_msgset_t set);
int mu_msgset_clear (mu_msgset_t set);
void mu_msgset_free (mu_msgset_t set);
void mu_msgset_destroy (mu_msgset_t *set);
  
int mu_msgset_parse_imap (mu_msgset_t set, int mode, const char *s,
			  char **end);

int mu_stream_msgset_format (mu_stream_t str,
			     struct mu_msgset_format const *fmt,
			     mu_msgset_t mset);

static inline int
mu_msgset_imap_print (mu_stream_t str, mu_msgset_t mset)
{
  return mu_stream_msgset_format (str, mu_msgset_fmt_imap, mset);
}
  
  
int mu_msgset_locate (mu_msgset_t msgset, size_t n,
		      struct mu_msgrange const **prange);

int mu_msgset_negate (mu_msgset_t msgset, mu_msgset_t *pnset);

int mu_msgset_count (mu_msgset_t mset, size_t *pcount);
int mu_msgset_is_empty (mu_msgset_t mset);

int mu_msgset_first (mu_msgset_t msgset, size_t *ret);
int mu_msgset_last (mu_msgset_t msgset, size_t *ret);
  
typedef int (*mu_msgset_msgno_action_t) (size_t _n, void *_call_data);
typedef int (*mu_msgset_message_action_t) (size_t _n, mu_message_t _msg,
					   void *_call_data);

#define MU_MSGSET_FOREACH_FORWARD  0x00
#define MU_MSGSET_FOREACH_BACKWARD 0x10

int mu_msgset_foreach_num (mu_msgset_t _msgset, int _flags,
			   mu_msgset_msgno_action_t _action,
			   void *_call_data);
  
int mu_msgset_foreach_dir_msgno (mu_msgset_t _msgset, int _dir,
				 mu_msgset_msgno_action_t _action,
				 void *_data);
int mu_msgset_foreach_msgno (mu_msgset_t _msgset,
			     mu_msgset_msgno_action_t _action,
			     void *_call_data);
int mu_msgset_foreach_dir_msguid (mu_msgset_t _msgset, int _dir,
				  mu_msgset_msgno_action_t _action,
				  void *_data);
int mu_msgset_foreach_msguid (mu_msgset_t _msgset,
			      mu_msgset_msgno_action_t _action,
			      void *_data);
  
int mu_msgset_foreach_dir_message (mu_msgset_t _msgset, int _dir,
				   mu_msgset_message_action_t _action,
				   void *_call_data);
int mu_msgset_foreach_message (mu_msgset_t _msgset,
			       mu_msgset_message_action_t _action,
			       void *_call_data);

  
#ifdef __cplusplus
}
#endif

#endif

Return to:

Send suggestions and report system problems to the System administrator.