isync.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* $Id$
  2. *
  3. * isync - IMAP4 to maildir mailbox synchronizer
  4. * Copyright (C) 2000 Michael R. Elkins <me@mutt.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <stdarg.h>
  21. #if HAVE_LIBSSL
  22. #include <openssl/ssl.h>
  23. #endif
  24. typedef struct
  25. {
  26. int fd;
  27. #if HAVE_LIBSSL
  28. SSL *ssl;
  29. unsigned int use_ssl:1;
  30. #endif
  31. } Socket_t;
  32. typedef struct
  33. {
  34. Socket_t *sock;
  35. char buf[1024];
  36. int bytes;
  37. int offset;
  38. }
  39. buffer_t;
  40. typedef struct config config_t;
  41. typedef struct mailbox mailbox_t;
  42. typedef struct message message_t;
  43. struct config
  44. {
  45. char *path;
  46. char *host;
  47. int port;
  48. char *user;
  49. char *pass;
  50. char *box;
  51. char *alias;
  52. config_t *next;
  53. #if HAVE_LIBSSL
  54. char *cert_file;
  55. unsigned int use_imaps:1;
  56. unsigned int require_ssl:1;
  57. #endif
  58. };
  59. /* struct representing local mailbox file */
  60. struct mailbox
  61. {
  62. char *path;
  63. message_t *msgs;
  64. unsigned int deleted; /* # of deleted messages */
  65. unsigned int uidvalidity;
  66. unsigned int changed:1;
  67. };
  68. /* message dispositions */
  69. #define D_SEEN (1<<0)
  70. #define D_ANSWERED (1<<1)
  71. #define D_DELETED (1<<2)
  72. #define D_FLAGGED (1<<3)
  73. #define D_RECENT (1<<4)
  74. #define D_DRAFT (1<<5)
  75. #define D_MAX 6
  76. struct message
  77. {
  78. char *file;
  79. unsigned int uid;
  80. unsigned int flags;
  81. message_t *next;
  82. unsigned int processed:1; /* message has already been evaluated */
  83. unsigned int new:1; /* message is in the new/ subdir */
  84. unsigned int changed:1; /* flags changed */
  85. unsigned int dead:1; /* message doesn't exist on the server */
  86. };
  87. /* struct used for parsing IMAP lists */
  88. typedef struct _list list_t;
  89. #define NIL (void*)0x1
  90. #define LIST (void*)0x2
  91. struct _list {
  92. char *val;
  93. list_t *next;
  94. list_t *child;
  95. };
  96. /* imap connection info */
  97. typedef struct
  98. {
  99. Socket_t *sock;
  100. unsigned int count; /* # of msgs */
  101. unsigned int recent; /* # of recent messages */
  102. buffer_t *buf; /* input buffer for reading server output */
  103. message_t *msgs; /* list of messages on the server */
  104. config_t *box; /* mailbox to open */
  105. message_t *recent_msgs; /* list of recent messages - only contains
  106. * UID to be used in a FETCH FLAGS command
  107. */
  108. unsigned int deleted; /* # of deleted messages */
  109. unsigned int uidvalidity;
  110. /* NAMESPACE info */
  111. list_t *ns_personal;
  112. list_t *ns_other;
  113. list_t *ns_shared;
  114. }
  115. imap_t;
  116. /* flags for sync_mailbox */
  117. #define SYNC_FAST (1<<0) /* don't sync flags, only fetch new msgs */
  118. #define SYNC_DELETE (1<<1) /* delete local that don't exist on server */
  119. #define SYNC_EXPUNGE (1<<2) /* don't fetch deleted messages */
  120. extern config_t global;
  121. extern unsigned int Tag;
  122. extern char Hostname[256];
  123. extern int Verbose;
  124. #if HAVE_LIBSSL
  125. extern SSL_CTX *SSLContext;
  126. #endif
  127. char *next_arg (char **);
  128. int sync_mailbox (mailbox_t *, imap_t *, int);
  129. void imap_close (imap_t *);
  130. int imap_fetch_message (imap_t *, unsigned int, int);
  131. int imap_set_flags (imap_t *, unsigned int, unsigned int);
  132. int imap_expunge (imap_t *);
  133. imap_t *imap_open (config_t *, int);
  134. mailbox_t *maildir_open (const char *, int fast);
  135. int maildir_expunge (mailbox_t *, int);
  136. int maildir_sync (mailbox_t *);
  137. int maildir_set_uidvalidity (mailbox_t *, unsigned int uidvalidity);
  138. /* parse an IMAP list construct */
  139. list_t * parse_list (char *s, char **end);
  140. int is_atom (list_t *list);
  141. int is_list (list_t *list);
  142. int is_nil (list_t *list);
  143. void free_list (list_t *list);