/[imapfilter]/imapfilter/imap.c
ViewVC logotype

Diff of /imapfilter/imap.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.23 by lefcha, Tue Jan 29 21:23:41 2002 UTC revision 1.24 by lefcha, Tue Jun 18 21:13:50 2002 UTC
# Line 9  Line 9 
9  #include "data.h"  #include "data.h"
10    
11    
12    extern int sockpri;
13    
14  static unsigned int tag = 0xF00000;     /* Every IMAP command is prefixed  static unsigned int tag = 0xF00000;     /* Every IMAP command is prefixed
15                                             with a unique [:alnum:] string. */                                             with a unique [:alnum:] string. */
16    
17  /*  /*
18   * Send to server data; a command.   * Send to server data; a command.
19   */   */
20  unsigned int send_command(char *cmd)  unsigned int send_command(int *sock, char *cmd)
21  {  {
22  #ifdef DEBUG  #ifdef DEBUG
23      printf("debug: sending command: %s", cmd);      printf("debug: sending command: %s", cmd);
24  #endif  #endif
25    
26      socket_write(cmd);      socket_write(sock, cmd);
27            
28      return tag++;      return tag++;
29  }  }
# Line 31  unsigned int send_command(char *cmd) Line 33  unsigned int send_command(char *cmd)
33  /*  /*
34   * IMAP NOOP: does nothing always succeeds.   * IMAP NOOP: does nothing always succeeds.
35   */   */
36  int imap_noop(void)  int imap_noop(int *sock)
37  {  {
38      char cmd[SMALL_CMD];      char cmd[SMALL_CMD];
39    
# Line 39  int imap_noop(void) Line 41  int imap_noop(void)
41    
42      snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag);      snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag);
43    
44      return send_command(cmd);      return send_command(sock, cmd);
45  }  }
46  #endif  #endif
47    
# Line 47  int imap_noop(void) Line 49  int imap_noop(void)
49  /*  /*
50   * IMAP CAPABILITY: requests listing of capabilities that the server supports.   * IMAP CAPABILITY: requests listing of capabilities that the server supports.
51   */   */
52  int imap_capability(void)  int imap_capability(int *sock)
53  {  {
54      char cmd[SMALL_CMD];      char cmd[SMALL_CMD];
55    
# Line 55  int imap_capability(void) Line 57  int imap_capability(void)
57    
58      snprintf(cmd, SMALL_CMD, "%X CAPABILITY\r\n", tag);      snprintf(cmd, SMALL_CMD, "%X CAPABILITY\r\n", tag);
59    
60      return send_command(cmd);      return send_command(sock, cmd);
61  }  }
62    
63    
# Line 63  int imap_capability(void) Line 65  int imap_capability(void)
65   * IMAP NAMESPACE: discovers the prefix and delimeter of namespaces used by   * IMAP NAMESPACE: discovers the prefix and delimeter of namespaces used by
66   * the server for mailboxes (RFC 2342).   * the server for mailboxes (RFC 2342).
67   */   */
68  int imap_namespace(void)  int imap_namespace(int *sock)
69  {  {
70      char cmd[SMALL_CMD];      char cmd[SMALL_CMD];
71    
# Line 71  int imap_namespace(void) Line 73  int imap_namespace(void)
73    
74      snprintf(cmd, SMALL_CMD, "%X NAMESPACE\r\n", tag);      snprintf(cmd, SMALL_CMD, "%X NAMESPACE\r\n", tag);
75    
76      return send_command(cmd);      return send_command(sock, cmd);
77  }  }
78    
79    
80  /*  /*
81   * IMAP LOGOUT: informs server that client is done.   * IMAP LOGOUT: informs server that client is done.
82   */   */
83  int imap_logout(void)  int imap_logout(int *sock)
84  {  {
85      char cmd[SMALL_CMD];      char cmd[SMALL_CMD];
86    
# Line 86  int imap_logout(void) Line 88  int imap_logout(void)
88    
89      snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);      snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);
90    
91      return send_command(cmd);      return send_command(sock, cmd);
92  }  }
93    
94    
95  /*  /*
96   * IMAP LOGIN: identifies client to server.   * IMAP LOGIN: identifies client to server.
97   */   */
98  int imap_login(char *user, char *pass)  int imap_login(int *sock, char *user, char *pass)
99  {  {
100      int r;      int r;
101      char *cmd;      char *cmd;
# Line 105  int imap_login(char *user, char *pass) Line 107  int imap_login(char *user, char *pass)
107      snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,      snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,
108               pass);               pass);
109    
110      r = send_command(cmd);      r = send_command(sock, cmd);
111            
112      sfree(cmd);      sfree(cmd);
113    
# Line 114  int imap_login(char *user, char *pass) Line 116  int imap_login(char *user, char *pass)
116    
117    
118  /*  /*
119   * IMAP EXAMINE: access a mailbox in READ-ONLY mode.   * IMAP LIST: returns a subset of names from the complete set of names
120     * available to the client.
121   *   *
122  int imap_examine(char *mbox)  int imap_list(int *sock, char *refer, char *mbox)
123    {
124        int r;
125        char cmd[BIG_CMD];
126        
127        verbose("Client request: LIST\n");
128        
129        snprintf(cmd, MEDIUM_CMD, "%X LIST \"%s\" \"%s\"\r\n", tag, refer,
130                 mbox);
131        
132        r = send_command(sock, cmd);
133        
134        return r;
135    }*/
136    
137    
138    /*
139     * IMAP SUBSCRIBE: adds the specified mailbox name to the server's
140     * set of "active" or "subscribed" mailboxes.
141     */
142    int imap_subscribe(int *sock, char *mbox)
143    {
144        char cmd[MEDIUM_CMD];
145    
146        verbose("Client request: SUBSCRIBE\n");
147    
148        snprintf(cmd, MEDIUM_CMD, "%X SUBSCRIBE \"%s\"\r\n", tag, mbox);
149    
150        return send_command(sock, cmd);
151    }
152    
153    
154    /*
155     * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
156     */
157    int imap_examine(int *sock, char *mbox)
158  {  {
159      char cmd[MEDIUM_CMD];      char cmd[MEDIUM_CMD];
160    
# Line 124  int imap_examine(char *mbox) Line 162  int imap_examine(char *mbox)
162    
163      snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);      snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);
164    
165      return send_command(cmd);      return send_command(sock, cmd);
166  }*/  }
167    
168    
169  /*  /*
170   * IMAP SELECT: access a mailbox in READ-WRITE mode.   * IMAP SELECT: access a mailbox in READ-WRITE mode.
171   */   */
172  int imap_select(char *mbox)  int imap_select(int *sock, char *mbox)
173  {  {
174      char cmd[SMALL_CMD];      char cmd[SMALL_CMD];
175    
# Line 139  int imap_select(char *mbox) Line 177  int imap_select(char *mbox)
177    
178      snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);      snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);
179    
180      return send_command(cmd);      return send_command(sock, cmd);
181  }  }
182    
183    
184  /*  /*
185   * IMAP STATUS: requests status of the indicated mailbox.   * IMAP STATUS: requests status of the indicated mailbox.
186   */   */
187  int imap_status(char *mbox, char *items)  int imap_status(int *sock, char *mbox, char *items)
188  {  {
189      char cmd[MEDIUM_CMD];      char cmd[MEDIUM_CMD];
190    
# Line 154  int imap_status(char *mbox, char *items) Line 192  int imap_status(char *mbox, char *items)
192    
193      snprintf(cmd, MEDIUM_CMD, "%X STATUS \"%s\" (%s)\r\n", tag, mbox, items);      snprintf(cmd, MEDIUM_CMD, "%X STATUS \"%s\" (%s)\r\n", tag, mbox, items);
194    
195      return send_command(cmd);      return send_command(sock, cmd);
196  }  }
197    
198    
199  /*  /*
200   * IMAP CREATE: create mailbox.   * IMAP CREATE: create mailbox.
201   */   */
202  int imap_create(char *mbox)  int imap_create(int *sock, char *mbox)
203  {  {
204      char cmd[MEDIUM_CMD];      char cmd[MEDIUM_CMD];
205    
# Line 169  int imap_create(char *mbox) Line 207  int imap_create(char *mbox)
207    
208      snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);      snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);
209    
210      return send_command(cmd);      return send_command(sock, cmd);
211  }  }
212    
213    
214  /*  /*
215   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
216   */   */
217  int imap_search(char *search)  int imap_search(int *sock, char *search)
218  {  {
219      char cmd[BIG_CMD];      char cmd[BIG_CMD];
220    
# Line 184  int imap_search(char *search) Line 222  int imap_search(char *search)
222    
223      snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);      snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);
224    
225      return send_command(cmd);      return send_command(sock, cmd);
226  }  }
227    
228    
229  /*  /*
230   * IMAP FETCH: retrieves data associated with a message.   * IMAP FETCH: retrieves data associated with a message.
231   */   */
232  int imap_fetch(char *mesg, char *headers, int peek)  int imap_fetch(int *sock, char *mesg, char *items)
233  {  {
234      char cmd[MEDIUM_CMD];      char cmd[MEDIUM_CMD];
235    
236      verbose("Client request: FETCH\n");      verbose("Client request: FETCH\n");
237    
238      snprintf(cmd, MEDIUM_CMD,      snprintf(cmd, MEDIUM_CMD,
239               "%X FETCH %s BODY%s[HEADER.FIELDS (%s)]\r\n", tag, mesg,               "%X FETCH %s %s\r\n", tag, mesg, items);
              (peek ? ".PEEK" : ""), headers);  
240    
241      return send_command(cmd);      return send_command(sock, cmd);
242  }  }
243    
244    
245  /*  /*
246   * IMAP STORE: alters data associated with a message.   * IMAP STORE: alters data associated with a message.
247   */   */
248  int imap_store(char *mesg, char *flags)  int imap_store(int *sock, char *mesg, char *flags)
249  {  {
250      char cmd[MEDIUM_CMD];      char cmd[MEDIUM_CMD];
251    
# Line 217  int imap_store(char *mesg, char *flags) Line 254  int imap_store(char *mesg, char *flags)
254      snprintf(cmd, MEDIUM_CMD, "%X STORE %s +FLAGS.SILENT (%s)\r\n", tag, mesg,      snprintf(cmd, MEDIUM_CMD, "%X STORE %s +FLAGS.SILENT (%s)\r\n", tag, mesg,
255               flags);               flags);
256    
257      return send_command(cmd);      return send_command(sock, cmd);
258  }  }
259    
260    
261  /*  /*
262   * IMAP COPY: copy messages to mailbox.   * IMAP COPY: copy messages to mailbox.
263   */   */
264  int imap_copy(char *mesg, char *mbox)  int imap_copy(int *sock, char *mesg, char *mbox)
265  {  {
266      char cmd[MEDIUM_CMD];      char cmd[MEDIUM_CMD];
267    
268      verbose("Client request: COPY\n");      verbose("Client request: COPY\n");
269    
270      snprintf(cmd, SMALL_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);      snprintf(cmd, MEDIUM_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);
271    
272      return send_command(cmd);      return send_command(sock, cmd);
273  }  }
274    
275    
276  /*  /*
277     * IMAP APPEND: append message to the end of a mailbox.
278     */
279    int imap_append(int *sock, char *mbox, unsigned int size)
280    {
281        char cmd[MEDIUM_CMD];
282        
283        verbose("Client request: APPEND\n");
284        
285        snprintf(cmd, MEDIUM_CMD, "%X APPEND \"%s\" {%d}\r\n", tag, mbox, size);
286        
287        return send_command(sock, cmd);
288    }
289    
290    
291    
292    /*
293   * IMAP CLOSE: delete messages and return to authenticated state.   * IMAP CLOSE: delete messages and return to authenticated state.
294   */   */
295  int imap_close(void)  int imap_close(int *sock)
296  {  {
297      char cmd[SMALL_CMD];      char cmd[SMALL_CMD];
298    
# Line 247  int imap_close(void) Line 300  int imap_close(void)
300    
301      snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);      snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);
302    
303      return send_command(cmd);      return send_command(sock, cmd);
304  }  }
305    
306    
307  /*  /*
308   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
309   *   *
310  int imap_expunge(void)  int imap_expunge(int *sock)
311  {  {
312      char cmd[SMALL_CMD];      char cmd[SMALL_CMD];
313    
# Line 262  int imap_expunge(void) Line 315  int imap_expunge(void)
315    
316      snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);      snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);
317    
318      return send_command(cmd);      return send_command(sock, cmd);
319  }*/  }*/

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26