libetpan - fdik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.7 KiB

  1. #include "xgmmsgid.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include "clist.h"
  6. #include "mailimap_types_helper.h"
  7. #include "mailimap_extension.h"
  8. #include "mailimap_keywords.h"
  9. #include "mailimap_parser.h"
  10. #include "mailimap_sender.h"
  11. #include "mailimap.h"
  12. enum {
  13. MAILIMAP_XGMMSGID_TYPE_MSGID
  14. };
  15. static int
  16. mailimap_xgmmsgid_extension_parse(int calling_parser, mailstream * fd,
  17. MMAPString * buffer, size_t * indx,
  18. struct mailimap_extension_data ** result,
  19. size_t progr_rate, progress_function * progr_fun);
  20. static void
  21. mailimap_xgmmsgid_extension_data_free(struct mailimap_extension_data * ext_data);
  22. LIBETPAN_EXPORT
  23. struct mailimap_extension_api mailimap_extension_xgmmsgid = {
  24. /* name */ "X-GM-MSGID",
  25. /* extension_id */ MAILIMAP_EXTENSION_XGMMSGID,
  26. /* parser */ mailimap_xgmmsgid_extension_parse,
  27. /* free */ mailimap_xgmmsgid_extension_data_free
  28. };
  29. static int fetch_data_xgmmsgid_parse(mailstream * fd,
  30. MMAPString * buffer, size_t * indx,
  31. uint64_t * result, size_t progr_rate, progress_function * progr_fun)
  32. {
  33. size_t cur_token;
  34. uint64_t msgid;
  35. int r;
  36. cur_token = * indx;
  37. r = mailimap_token_case_insensitive_parse(fd, buffer,
  38. &cur_token, "X-GM-MSGID");
  39. if (r != MAILIMAP_NO_ERROR)
  40. return r;
  41. r = mailimap_space_parse(fd, buffer, &cur_token);
  42. if (r != MAILIMAP_NO_ERROR)
  43. return r;
  44. r = mailimap_uint64_parse(fd, buffer, &cur_token, &msgid);
  45. if (r != MAILIMAP_NO_ERROR)
  46. return r;
  47. * indx = cur_token;
  48. * result = msgid;
  49. return MAILIMAP_NO_ERROR;
  50. }
  51. static int
  52. mailimap_xgmmsgid_extension_parse(int calling_parser, mailstream * fd,
  53. MMAPString * buffer, size_t * indx,
  54. struct mailimap_extension_data ** result,
  55. size_t progr_rate, progress_function * progr_fun)
  56. {
  57. size_t cur_token;
  58. uint64_t msgid;
  59. uint64_t * data_msgid;
  60. struct mailimap_extension_data * ext_data;
  61. int r;
  62. cur_token = * indx;
  63. switch (calling_parser)
  64. {
  65. case MAILIMAP_EXTENDED_PARSER_FETCH_DATA:
  66. r = fetch_data_xgmmsgid_parse(fd, buffer, &cur_token, &msgid, progr_rate, progr_fun);
  67. if (r != MAILIMAP_NO_ERROR)
  68. return r;
  69. data_msgid = malloc(sizeof(* data_msgid));
  70. if (data_msgid == NULL) {
  71. return MAILIMAP_ERROR_MEMORY;
  72. }
  73. * data_msgid = msgid;
  74. ext_data = mailimap_extension_data_new(&mailimap_extension_xgmmsgid,
  75. MAILIMAP_XGMMSGID_TYPE_MSGID, data_msgid);
  76. if (ext_data == NULL) {
  77. free(data_msgid);
  78. return MAILIMAP_ERROR_MEMORY;
  79. }
  80. * result = ext_data;
  81. * indx = cur_token;
  82. return MAILIMAP_NO_ERROR;
  83. default:
  84. return MAILIMAP_ERROR_PARSE;
  85. }
  86. }
  87. static void
  88. mailimap_xgmmsgid_extension_data_free(struct mailimap_extension_data * ext_data)
  89. {
  90. free(ext_data->ext_data);
  91. free(ext_data);
  92. }
  93. struct mailimap_fetch_att * mailimap_fetch_att_new_xgmmsgid(void)
  94. {
  95. char * keyword;
  96. struct mailimap_fetch_att * att;
  97. keyword = strdup("X-GM-MSGID");
  98. if (keyword == NULL)
  99. return NULL;
  100. att = mailimap_fetch_att_new_extension(keyword);
  101. if (att == NULL) {
  102. free(keyword);
  103. return NULL;
  104. }
  105. return att;
  106. }