summaryrefslogtreecommitdiff
path: root/dbmail-imapsession.h
blob: f2da728a2e27d29b015934687717f8dd36098046 (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
/*
 *
 * Copyright (c) 2005-2006 NFG Net Facilities Group BV support@nfg.nl
 *
 */
	
#ifndef _DBMAIL_COMMANDCHANNEL_H
#define _DBMAIL_COMMANDCHANNEL_H

#include "dbmail.h"

/* ImapSession definition */
struct ImapSession {
	clientinfo_t *ci;
	u64_t msg_idnr;  // replace this with a GList
	GMimeStream *fstream; // gmime filter wrapper around the TX handler in clientinfo_t
	GString *buff; // use buffered writes
	gboolean use_uid;
	char *tag;
	char *command;
	int command_type;
	int timeout;
	char **args;
	u64_t args_idx;
	fetch_items_t *fi;
	struct DbmailMailbox *mailbox;
	struct DbmailMessage *message;
	GTree *ids;
	GTree *headers;
	GTree *envelopes;
	GTree *msginfo;
	GList *recent;
	GList *ids_list;
	gpointer cmd; // command structure
	gboolean error; // command result
};

typedef struct {
	gboolean silent;
	int action;
	int flaglist[IMAP_NFLAGS];
	int msgflags[IMAP_NFLAGS];
} cmd_store_t;

typedef struct {
	u64_t mailbox_id;
} cmd_copy_t;

typedef int (*IMAP_COMMAND_HANDLER) (struct ImapSession *);

struct ImapSession * dbmail_imap_session_new(void);
struct ImapSession * dbmail_imap_session_setClientinfo(struct ImapSession * self, clientinfo_t *ci);
struct ImapSession * dbmail_imap_session_setTag(struct ImapSession * self, char * tag);
struct ImapSession * dbmail_imap_session_setCommand(struct ImapSession * self, char * command);
struct ImapSession * dbmail_imap_session_setArgs(struct ImapSession * self, char ** args);
struct ImapSession * dbmail_imap_session_resetFi(struct ImapSession * self);



void dbmail_imap_session_args_free(struct ImapSession *self, gboolean all);

void dbmail_imap_session_fetch_free(struct ImapSession *self);
void dbmail_imap_session_delete(struct ImapSession * self);

int dbmail_imap_session_readln(struct ImapSession * self, char * buffer);
int dbmail_imap_session_discard_to_eol(struct ImapSession *self);

/* \return
 *   -1 on possibly recoverable errors
 *   -2 on serious unrecoverable errors
 */
void dbmail_imap_session_buff_clear(struct ImapSession *self);
void dbmail_imap_session_buff_append(struct ImapSession *self, char *message, ...);
void dbmail_imap_session_buff_flush(struct ImapSession *self);
int dbmail_imap_session_printf(struct ImapSession * self, char * message, ...);

int dbmail_imap_session_set_state(struct ImapSession *self, int state);
int client_is_authenticated(struct ImapSession * self);
int check_state_and_args(struct ImapSession * self, const char * command, int minargs, int maxargs, int state);
int dbmail_imap_session_handle_auth(struct ImapSession * self, char * username, char * password);
int dbmail_imap_session_prompt(struct ImapSession * self, char * prompt, char * value);
u64_t dbmail_imap_session_mailbox_get_idnr(struct ImapSession * self, const char * mailbox);
int dbmail_imap_session_mailbox_check_acl(struct ImapSession * self, u64_t idnr, ACLRight_t right);
int dbmail_imap_session_mailbox_get_selectable(struct ImapSession * self, u64_t idnr);

int dbmail_imap_session_mailbox_status(struct ImapSession * self, gboolean update);
int dbmail_imap_session_idle(struct ImapSession *self);
int dbmail_imap_session_mailbox_show_info(struct ImapSession * self);
int dbmail_imap_session_mailbox_open(struct ImapSession * self, const char * mailbox);
int dbmail_imap_session_mailbox_close(struct ImapSession *self);

int dbmail_imap_session_mailbox_select_recent(struct ImapSession *self);
int dbmail_imap_session_mailbox_update_recent(struct ImapSession *self);

int dbmail_imap_session_fetch_parse_args(struct ImapSession * self);
GTree * dbmail_imap_session_get_msginfo(struct ImapSession *self, GTree *ids);
int dbmail_imap_session_fetch_get_items(struct ImapSession *self);

void dbmail_imap_session_bodyfetch_new(struct ImapSession *self);
void dbmail_imap_session_bodyfetch_free(struct ImapSession *self);
body_fetch_t * dbmail_imap_session_bodyfetch_get_last(struct ImapSession *self);
void dbmail_imap_session_bodyfetch_rewind(struct ImapSession *self);

int dbmail_imap_session_bodyfetch_set_partspec(struct ImapSession *self, char *partspec, int length);
char *dbmail_imap_session_bodyfetch_get_last_partspec(struct ImapSession *self);

int dbmail_imap_session_bodyfetch_set_itemtype(struct ImapSession *self, int itemtype);
int dbmail_imap_session_bodyfetch_get_last_itemtype(struct ImapSession *self);

int dbmail_imap_session_bodyfetch_set_argstart(struct ImapSession *self);
int dbmail_imap_session_bodyfetch_get_last_argstart(struct ImapSession *self);

int dbmail_imap_session_bodyfetch_set_argcnt(struct ImapSession *self);
int dbmail_imap_session_bodyfetch_get_last_argcnt(struct ImapSession *self);

int dbmail_imap_session_bodyfetch_set_octetstart(struct ImapSession *self, guint64 octet);
guint64 dbmail_imap_session_bodyfetch_get_last_octetstart(struct ImapSession *self);

int dbmail_imap_session_bodyfetch_set_octetcnt(struct ImapSession *self, guint64 octet);
guint64 dbmail_imap_session_bodyfetch_get_last_octetcnt(struct ImapSession *self);

char **build_args_array_ext(struct ImapSession *self, const char *originalString);

#endif