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

Diff of /imapfilter/imap.c

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

revision 1.29 by lefcha, Fri Feb 21 18:55:15 2003 UTC revision 1.30 by lefcha, Sat Feb 22 16:06:41 2003 UTC
# Line 11  Line 11 
11    
12  extern int sockpri;  extern int sockpri;
13    
14  static unsigned int tag = 0xF00000;     /* Every IMAP command is prefixed  static unsigned int tag = 0xA00000;     /* Every IMAP command is prefixed with
15                                             with a unique [:alnum:] string. */                                           * 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(int *sock, char *cmd)  unsigned int
21    send_command(int *sock, char *cmd)
22  {  {
23  #ifdef DEBUG  #ifdef DEBUG
24      fprintf(stderr, "debug: sending command: %s", cmd);          fprintf(stderr, "debug: sending command: %s", cmd);
25  #endif  #endif
26    
27      socket_write(sock, cmd);          socket_write(sock, cmd);
28    
29      return tag++;          return tag++;
30  }  }
31    
32    
# Line 33  unsigned int send_command(int *sock, cha Line 34  unsigned int send_command(int *sock, cha
34  /*  /*
35   * IMAP NOOP: does nothing always succeeds.   * IMAP NOOP: does nothing always succeeds.
36   */   */
37  int imap_noop(int *sock)  int
38    imap_noop(int *sock)
39  {  {
40      char cmd[SMALL_CMD];          char cmd[SMALL_CMD];
41    
42      verbose("Client request: NOOP\n");          verbose("Client request: NOOP\n");
43    
44      snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag);          snprintf(cmd, SMALL_CMD, "%X NOOP\r\n", tag);
45    
46      return send_command(sock, cmd);          return send_command(sock, cmd);
47  }  }
48    
49  #endif  #endif
# Line 50  int imap_noop(int *sock) Line 52  int imap_noop(int *sock)
52  /*  /*
53   * IMAP CAPABILITY: requests listing of capabilities that the server supports.   * IMAP CAPABILITY: requests listing of capabilities that the server supports.
54   */   */
55  int imap_capability(int *sock)  int
56    imap_capability(int *sock)
57  {  {
58      char cmd[SMALL_CMD];          char cmd[SMALL_CMD];
59    
60      verbose("Client request: CAPABILITY\n");          verbose("Client request: CAPABILITY\n");
61    
62      snprintf(cmd, SMALL_CMD, "%X CAPABILITY\r\n", tag);          snprintf(cmd, SMALL_CMD, "%X CAPABILITY\r\n", tag);
63    
64      return send_command(sock, cmd);          return send_command(sock, cmd);
65  }  }
66    
67    
# Line 66  int imap_capability(int *sock) Line 69  int imap_capability(int *sock)
69   * IMAP NAMESPACE: discovers the prefix and delimeter of namespaces used by   * IMAP NAMESPACE: discovers the prefix and delimeter of namespaces used by
70   * the server for mailboxes (RFC 2342).   * the server for mailboxes (RFC 2342).
71   */   */
72  int imap_namespace(int *sock)  int
73    imap_namespace(int *sock)
74  {  {
75      char cmd[SMALL_CMD];          char cmd[SMALL_CMD];
76    
77      verbose("Client request: NAMESPACE\n");          verbose("Client request: NAMESPACE\n");
78    
79      snprintf(cmd, SMALL_CMD, "%X NAMESPACE\r\n", tag);          snprintf(cmd, SMALL_CMD, "%X NAMESPACE\r\n", tag);
80    
81      return send_command(sock, cmd);          return send_command(sock, cmd);
82  }  }
83    
84    
85  /*  /*
86   * IMAP LOGOUT: informs server that client is done.   * IMAP LOGOUT: informs server that client is done.
87   */   */
88  int imap_logout(int *sock)  int
89    imap_logout(int *sock)
90  {  {
91      char cmd[SMALL_CMD];          char cmd[SMALL_CMD];
92    
93      verbose("Client request: LOGOUT\n");          verbose("Client request: LOGOUT\n");
94    
95      snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);          snprintf(cmd, SMALL_CMD, "%X LOGOUT\r\n", tag);
96    
97      return send_command(sock, cmd);          return send_command(sock, cmd);
98  }  }
99    
100    
# Line 97  int imap_logout(int *sock) Line 102  int imap_logout(int *sock)
102   * IMAP AUTHENTICATE: indicates authentication mechanism and performs an   * IMAP AUTHENTICATE: indicates authentication mechanism and performs an
103   * authentication protocol exchange.   * authentication protocol exchange.
104   */   */
105  int imap_authenticate(int *sock, char *auth)  int
106    imap_authenticate(int *sock, char *auth)
107  {  {
108      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
109        
110      verbose("Client request: AUTHENTICATE\n");          verbose("Client request: AUTHENTICATE\n");
111                
112      snprintf(cmd, MEDIUM_CMD, "%X AUTHENTICATE %s\r\n", tag, auth);          snprintf(cmd, MEDIUM_CMD, "%X AUTHENTICATE %s\r\n", tag, auth);
113        
114      return send_command(sock, cmd);          return send_command(sock, cmd);
115  }  }
116    
117    
118  /*  /*
119   * IMAP LOGIN: identifies client to server.   * IMAP LOGIN: identifies client to server.
120   */   */
121  int imap_login(int *sock, char *user, char *pass)  int
122    imap_login(int *sock, char *user, char *pass)
123  {  {
124      int r;          int r;
125      char *cmd;          char *cmd;
126    
127      cmd = (char *)smalloc(MEDIUM_CMD);          cmd = (char *)smalloc(MEDIUM_CMD);
128    
129      verbose("Client request: LOGIN\n");          verbose("Client request: LOGIN\n");
130    
131      snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,          snprintf(cmd, MEDIUM_CMD, "%X LOGIN \"%s\" \"%s\"\r\n", tag, user,
132               pass);              pass);
133    
134      r = send_command(sock, cmd);          r = send_command(sock, cmd);
135    
136      sfree(cmd);          sfree(cmd);
137    
138      return r;          return r;
139  }  }
140    
141    
# Line 156  int imap_list(int *sock, char *refer, ch Line 163  int imap_list(int *sock, char *refer, ch
163   * IMAP SUBSCRIBE: adds the specified mailbox name to the server's   * IMAP SUBSCRIBE: adds the specified mailbox name to the server's
164   * set of "active" or "subscribed" mailboxes.   * set of "active" or "subscribed" mailboxes.
165   */   */
166  int imap_subscribe(int *sock, char *mbox)  int
167    imap_subscribe(int *sock, char *mbox)
168  {  {
169      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
170    
171      verbose("Client request: SUBSCRIBE\n");          verbose("Client request: SUBSCRIBE\n");
172    
173      snprintf(cmd, MEDIUM_CMD, "%X SUBSCRIBE \"%s\"\r\n", tag, mbox);          snprintf(cmd, MEDIUM_CMD, "%X SUBSCRIBE \"%s\"\r\n", tag, mbox);
174    
175      return send_command(sock, cmd);          return send_command(sock, cmd);
176  }  }
177    
178    
179  /*  /*
180   * IMAP EXAMINE: access a mailbox in READ-ONLY mode.   * IMAP EXAMINE: access a mailbox in READ-ONLY mode.
181   */   */
182  int imap_examine(int *sock, char *mbox)  int
183    imap_examine(int *sock, char *mbox)
184  {  {
185      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
186    
187      verbose("Client request: EXAMINE %s\n", mbox);          verbose("Client request: EXAMINE %s\n", mbox);
188    
189      snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);          snprintf(cmd, MEDIUM_CMD, "%X EXAMINE \"%s\"\r\n", tag, mbox);
190    
191      return send_command(sock, cmd);          return send_command(sock, cmd);
192  }  }
193    
194    
195  /*  /*
196   * IMAP SELECT: access a mailbox in READ-WRITE mode.   * IMAP SELECT: access a mailbox in READ-WRITE mode.
197   */   */
198  int imap_select(int *sock, char *mbox)  int
199    imap_select(int *sock, char *mbox)
200  {  {
201      char cmd[SMALL_CMD];          char cmd[SMALL_CMD];
202    
203      verbose("Client request: SELECT\n");          verbose("Client request: SELECT\n");
204    
205      snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);          snprintf(cmd, SMALL_CMD, "%X SELECT \"%s\"\r\n", tag, mbox);
206    
207      return send_command(sock, cmd);          return send_command(sock, cmd);
208  }  }
209    
210    
211  /*  /*
212   * IMAP STATUS: requests status of the indicated mailbox.   * IMAP STATUS: requests status of the indicated mailbox.
213   */   */
214  int imap_status(int *sock, char *mbox, char *items)  int
215    imap_status(int *sock, char *mbox, char *items)
216  {  {
217      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
218    
219      verbose("Client request: STATUS\n");          verbose("Client request: STATUS\n");
220    
221      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);
222    
223      return send_command(sock, cmd);          return send_command(sock, cmd);
224  }  }
225    
226    
227  /*  /*
228   * IMAP CREATE: create mailbox.   * IMAP CREATE: create mailbox.
229   */   */
230  int imap_create(int *sock, char *mbox)  int
231    imap_create(int *sock, char *mbox)
232  {  {
233      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
234    
235      verbose("Client request: CREATE\n");          verbose("Client request: CREATE\n");
236    
237      snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);          snprintf(cmd, MEDIUM_CMD, "%X CREATE \"%s\"\r\n", tag, mbox);
238    
239      return send_command(sock, cmd);          return send_command(sock, cmd);
240  }  }
241    
242    
243  /*  /*
244   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.   * IMAP SEARCH: searches the mailbox for messages that match certain criteria.
245   */   */
246  int imap_search(int *sock, char *charset, char *search)  int
247    imap_search(int *sock, char *charset, char *search)
248  {  {
249      char cmd[BIG_CMD];          char cmd[BIG_CMD];
250    
251      verbose("Client request: SEARCH\n");          verbose("Client request: SEARCH\n");
252    
253      if (*charset)          if (*charset)
254          snprintf(cmd, BIG_CMD, "%X SEARCH CHARSET \"%s\" %s\r\n", tag,                  snprintf(cmd, BIG_CMD, "%X SEARCH CHARSET \"%s\" %s\r\n", tag,
255                   charset, search);                      charset, search);
256      else          else
257          snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);                  snprintf(cmd, BIG_CMD, "%X SEARCH %s\r\n", tag, search);
258    
259      return send_command(sock, cmd);          return send_command(sock, cmd);
260  }  }
261    
262    
263  /*  /*
264   * IMAP FETCH: retrieves data associated with a message.   * IMAP FETCH: retrieves data associated with a message.
265   */   */
266  int imap_fetch(int *sock, char *mesg, char *items)  int
267    imap_fetch(int *sock, char *mesg, char *items)
268  {  {
269      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
270    
271      verbose("Client request: FETCH\n");          verbose("Client request: FETCH\n");
272    
273      snprintf(cmd, MEDIUM_CMD,          snprintf(cmd, MEDIUM_CMD, "%X FETCH %s %s\r\n", tag, mesg, items);
              "%X FETCH %s %s\r\n", tag, mesg, items);  
274    
275      return send_command(sock, cmd);          return send_command(sock, cmd);
276  }  }
277    
278    
279  /*  /*
280   * IMAP STORE: alters data associated with a message.   * IMAP STORE: alters data associated with a message.
281   */   */
282  int imap_store(int *sock, char *mesg, unsigned int mode, char *flags)  int
283    imap_store(int *sock, char *mesg, unsigned int mode, char *flags)
284  {  {
285      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
286    
287      verbose("Client request: STORE\n");          verbose("Client request: STORE\n");
288    
289      snprintf(cmd, MEDIUM_CMD, "%X STORE %s %sFLAGS.SILENT (%s)\r\n", tag, mesg,          snprintf(cmd, MEDIUM_CMD, "%X STORE %s %sFLAGS.SILENT (%s)\r\n", tag,
290               (mode == STORE_FLAG_REPLACE ? "" :              mesg, (mode == STORE_FLAG_REPLACE ? "" :
291                mode == STORE_FLAG_ADD ? "+" : "-"), flags);                  mode == STORE_FLAG_ADD ? "+" : "-"), flags);
292    
293      return send_command(sock, cmd);          return send_command(sock, cmd);
294  }  }
295    
296    
297  /*  /*
298   * IMAP COPY: copy messages to mailbox.   * IMAP COPY: copy messages to mailbox.
299   */   */
300  int imap_copy(int *sock, char *mesg, char *mbox)  int
301    imap_copy(int *sock, char *mesg, char *mbox)
302  {  {
303      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
304    
305      verbose("Client request: COPY\n");          verbose("Client request: COPY\n");
306    
307      snprintf(cmd, MEDIUM_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);          snprintf(cmd, MEDIUM_CMD, "%X COPY %s \"%s\"\r\n", tag, mesg, mbox);
308    
309      return send_command(sock, cmd);          return send_command(sock, cmd);
310  }  }
311    
312    
313  /*  /*
314   * IMAP APPEND: append message to the end of a mailbox.   * IMAP APPEND: append message to the end of a mailbox.
315   */   */
316  int imap_append(int *sock, char *mbox, unsigned int size)  int
317    imap_append(int *sock, char *mbox, unsigned int size)
318  {  {
319      char cmd[MEDIUM_CMD];          char cmd[MEDIUM_CMD];
320    
321      verbose("Client request: APPEND\n");          verbose("Client request: APPEND\n");
322    
323      snprintf(cmd, MEDIUM_CMD, "%X APPEND \"%s\" {%d}\r\n", tag, mbox, size);          snprintf(cmd, MEDIUM_CMD, "%X APPEND \"%s\" {%d}\r\n", tag, mbox, size);
324    
325      return send_command(sock, cmd);          return send_command(sock, cmd);
326  }  }
327    
328    
# Line 314  int imap_append(int *sock, char *mbox, u Line 330  int imap_append(int *sock, char *mbox, u
330  /*  /*
331   * IMAP CLOSE: delete messages and return to authenticated state.   * IMAP CLOSE: delete messages and return to authenticated state.
332   */   */
333  int imap_close(int *sock)  int
334    imap_close(int *sock)
335  {  {
336      char cmd[SMALL_CMD];          char cmd[SMALL_CMD];
337    
338      verbose("Client request: CLOSE\n");          verbose("Client request: CLOSE\n");
339    
340      snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);          snprintf(cmd, SMALL_CMD, "%X CLOSE\r\n", tag);
341    
342      return send_command(sock, cmd);          return send_command(sock, cmd);
343  }  }
344    
345    
346  /*  /*
347   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.   * IMAP EXPUNGE: permanently removes any messages with the \Deleted flag set.
348   */   */
349  int imap_expunge(int *sock)  int
350    imap_expunge(int *sock)
351  {  {
352      char cmd[SMALL_CMD];          char cmd[SMALL_CMD];
353    
354      verbose("Client request: EXPUNGE\n");          verbose("Client request: EXPUNGE\n");
355    
356      snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);          snprintf(cmd, SMALL_CMD, "%X EXPUNGE\r\n", tag);
357    
358      return send_command(sock, cmd);          return send_command(sock, cmd);
359  }  }

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26