Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

implemented X-GM-LABELS store

  • Loading branch information...
commit ee0cae2b031e1deb6d2c4a9479d3433e40bb0747 1 parent 86a0801
Hoà V. DINH authored December 29, 2011
199  src/low-level/imap/xgmlabels.c
@@ -40,6 +40,8 @@
40 40
 #include "mailimap_extension.h"
41 41
 #include "mailimap_keywords.h"
42 42
 #include "mailimap_parser.h"
  43
+#include "mailimap_sender.h"
  44
+#include "mailimap.h"
43 45
 
44 46
 struct mailimap_fetch_att * mailimap_fetch_att_new_xgmlabels(void)
45 47
 {
@@ -284,3 +286,200 @@ mailimap_xgmlabels_extension_data_free(struct mailimap_extension_data * ext_data
284 286
   }
285 287
   free(ext_data);
286 288
 }
  289
+
  290
+static int mailimap_oparenth_send(mailstream * fd)
  291
+{
  292
+  return mailimap_char_send(fd, '(');
  293
+}
  294
+
  295
+static int mailimap_cparenth_send(mailstream * fd)
  296
+{
  297
+  return mailimap_char_send(fd, ')');
  298
+}
  299
+
  300
+static int mailimap_msg_att_xgmlabels_send(mailstream * fd, struct mailimap_msg_att_xgmlabels * labels)
  301
+{
  302
+  int r;
  303
+  
  304
+  r = mailimap_oparenth_send(fd);
  305
+  if (r != MAILIMAP_NO_ERROR)
  306
+    return r;
  307
+  
  308
+  if (labels->att_labels != NULL) {
  309
+    r = mailimap_struct_spaced_list_send(fd, labels->att_labels,
  310
+                                         (mailimap_struct_sender *) mailimap_astring_send);
  311
+    if (r != MAILIMAP_NO_ERROR)
  312
+      return r;
  313
+  }
  314
+  
  315
+  r = mailimap_cparenth_send(fd);
  316
+  if (r != MAILIMAP_NO_ERROR)
  317
+    return r;
  318
+  
  319
+  return MAILIMAP_NO_ERROR;
  320
+}
  321
+
  322
+static int mailimap_store_xgmlabels_send(mailstream * fd, struct mailimap_set * set,
  323
+                                         int fl_sign, int fl_silent,
  324
+                                         struct mailimap_msg_att_xgmlabels * labels)
  325
+{
  326
+  int r;
  327
+  
  328
+  r = mailimap_token_send(fd, "STORE");
  329
+  if (r != MAILIMAP_NO_ERROR)
  330
+    return r;
  331
+  r = mailimap_space_send(fd);
  332
+  if (r != MAILIMAP_NO_ERROR)
  333
+    return r;
  334
+  r = mailimap_set_send(fd, set);
  335
+  if (r != MAILIMAP_NO_ERROR)
  336
+    return r;
  337
+  r = mailimap_space_send(fd);
  338
+  if (r != MAILIMAP_NO_ERROR)
  339
+    return r;
  340
+  
  341
+  switch (fl_sign) {
  342
+    case 1:
  343
+      r = mailimap_char_send(fd, '+');
  344
+      if (r != MAILIMAP_NO_ERROR)
  345
+        return r;
  346
+      break;
  347
+    case -1:
  348
+      r = mailimap_char_send(fd, '-');
  349
+      if (r != MAILIMAP_NO_ERROR)
  350
+        return r;
  351
+      break;
  352
+  }
  353
+  
  354
+  r = mailimap_token_send(fd, "X-GM-LABELS");
  355
+  if (r != MAILIMAP_NO_ERROR)
  356
+    return r;
  357
+  
  358
+  if (fl_silent) {
  359
+    r = mailimap_token_send(fd, ".SILENT");
  360
+    if (r != MAILIMAP_NO_ERROR)
  361
+      return r;
  362
+  }
  363
+  
  364
+  r = mailimap_space_send(fd);
  365
+  if (r != MAILIMAP_NO_ERROR)
  366
+    return r;
  367
+  
  368
+  r = mailimap_msg_att_xgmlabels_send(fd, labels);
  369
+  if (r != MAILIMAP_NO_ERROR)
  370
+    return r;
  371
+  
  372
+  return MAILIMAP_NO_ERROR;
  373
+}
  374
+
  375
+static int mailimap_uid_store_xgmlabels_send(mailstream * fd, struct mailimap_set * set,
  376
+                                             int fl_sign, int fl_silent,
  377
+                                             struct mailimap_msg_att_xgmlabels * labels)
  378
+{
  379
+  int r;
  380
+  
  381
+  r = mailimap_token_send(fd, "UID");
  382
+  if (r != MAILIMAP_NO_ERROR)
  383
+    return r;
  384
+  r = mailimap_space_send(fd);
  385
+  if (r != MAILIMAP_NO_ERROR)
  386
+    return r;
  387
+  
  388
+  return mailimap_store_xgmlabels_send(fd, set, fl_sign, fl_silent, labels);
  389
+}
  390
+
  391
+int
  392
+mailimap_store_xgmlabels(mailimap * session,
  393
+                         struct mailimap_set * set,
  394
+                         int fl_sign, int fl_silent,
  395
+                         struct mailimap_msg_att_xgmlabels * labels)
  396
+{
  397
+  struct mailimap_response * response;
  398
+  int r;
  399
+  int error_code;
  400
+  
  401
+  if (session->imap_state != MAILIMAP_STATE_SELECTED)
  402
+    return MAILIMAP_ERROR_BAD_STATE;
  403
+  
  404
+  r = mailimap_send_current_tag(session);
  405
+  if (r != MAILIMAP_NO_ERROR)
  406
+    return r;
  407
+  
  408
+  r = mailimap_store_xgmlabels_send(session->imap_stream, set, fl_sign, fl_silent, labels);
  409
+  if (r != MAILIMAP_NO_ERROR)
  410
+    return r;
  411
+  
  412
+  r = mailimap_crlf_send(session->imap_stream);
  413
+  if (r != MAILIMAP_NO_ERROR)
  414
+    return r;
  415
+  
  416
+  if (mailstream_flush(session->imap_stream) == -1)
  417
+    return MAILIMAP_ERROR_STREAM;
  418
+  
  419
+  if (mailimap_read_line(session) == NULL)
  420
+    return MAILIMAP_ERROR_STREAM;
  421
+  
  422
+  r = mailimap_parse_response(session, &response);
  423
+  if (r != MAILIMAP_NO_ERROR)
  424
+    return r;
  425
+  
  426
+  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  427
+  
  428
+  mailimap_response_free(response);
  429
+  
  430
+  switch (error_code) {
  431
+    case MAILIMAP_RESP_COND_STATE_OK:
  432
+      return MAILIMAP_NO_ERROR;
  433
+      
  434
+    default:
  435
+      return MAILIMAP_ERROR_STORE;
  436
+  }
  437
+}
  438
+
  439
+int
  440
+mailimap_uid_store_xgmlabels(mailimap * session,
  441
+                             struct mailimap_set * set,
  442
+                             int fl_sign, int fl_silent,
  443
+                             struct mailimap_msg_att_xgmlabels * labels)
  444
+{
  445
+  struct mailimap_response * response;
  446
+  int r;
  447
+  int error_code;
  448
+  
  449
+  if (session->imap_state != MAILIMAP_STATE_SELECTED)
  450
+    return MAILIMAP_ERROR_BAD_STATE;
  451
+  
  452
+  r = mailimap_send_current_tag(session);
  453
+  if (r != MAILIMAP_NO_ERROR)
  454
+    return r;
  455
+  
  456
+  r = mailimap_uid_store_xgmlabels_send(session->imap_stream, set, fl_sign, fl_silent, labels);
  457
+  if (r != MAILIMAP_NO_ERROR)
  458
+    return r;
  459
+  
  460
+  r = mailimap_crlf_send(session->imap_stream);
  461
+  if (r != MAILIMAP_NO_ERROR)
  462
+    return r;
  463
+  
  464
+  if (mailstream_flush(session->imap_stream) == -1)
  465
+    return MAILIMAP_ERROR_STREAM;
  466
+  
  467
+  if (mailimap_read_line(session) == NULL)
  468
+    return MAILIMAP_ERROR_STREAM;
  469
+  
  470
+  r = mailimap_parse_response(session, &response);
  471
+  if (r != MAILIMAP_NO_ERROR)
  472
+    return r;
  473
+  
  474
+  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
  475
+  
  476
+  mailimap_response_free(response);
  477
+  
  478
+  switch (error_code) {
  479
+    case MAILIMAP_RESP_COND_STATE_OK:
  480
+      return MAILIMAP_NO_ERROR;
  481
+      
  482
+    default:
  483
+      return MAILIMAP_ERROR_UID_STORE;
  484
+  }
  485
+}
14  src/low-level/imap/xgmlabels.h
@@ -63,6 +63,20 @@ extern "C" {
63 63
   
64 64
   LIBETPAN_EXPORT void mailimap_msg_att_xgmlabels_free(struct mailimap_msg_att_xgmlabels * att);
65 65
   
  66
+  LIBETPAN_EXPORT
  67
+  int
  68
+  mailimap_store_xgmlabels(mailimap * session,
  69
+                           struct mailimap_set * set,
  70
+                           int fl_sign, int fl_silent,
  71
+                           struct mailimap_msg_att_xgmlabels * labels);
  72
+  
  73
+  LIBETPAN_EXPORT
  74
+  int
  75
+  mailimap_uid_store_xgmlabels(mailimap * session,
  76
+                               struct mailimap_set * set,
  77
+                               int fl_sign, int fl_silent,
  78
+                               struct mailimap_msg_att_xgmlabels * labels);
  79
+  
66 80
 #ifdef __cplusplus
67 81
 }
68 82
 #endif

0 notes on commit ee0cae2

Please sign in to comment.
Something went wrong with that request. Please try again.