isync.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. char *copy_deleted_to;
  53. off_t max_size;
  54. config_t *next;
  55. #if HAVE_LIBSSL
  56. char *cert_file;
  57. unsigned int use_imaps:1;
  58. unsigned int require_ssl:1;
  59. unsigned int use_sslv2:1;
  60. unsigned int use_sslv3:1;
  61. unsigned int use_tlsv1:1;
  62. unsigned int require_cram:1;
  63. #endif
  64. unsigned int use_namespace:1;
  65. unsigned int expunge:1;
  66. };
  67. /* struct representing local mailbox file */
  68. struct mailbox
  69. {
  70. char *path;
  71. message_t *msgs;
  72. unsigned int deleted; /* # of deleted messages */
  73. unsigned int uidvalidity;
  74. unsigned int maxuid; /* largest uid we know about */
  75. unsigned int changed:1;
  76. unsigned int maxuidchanged:1;
  77. };
  78. /* message dispositions */
  79. #define D_SEEN (1<<0)
  80. #define D_ANSWERED (1<<1)
  81. #define D_DELETED (1<<2)
  82. #define D_FLAGGED (1<<3)
  83. #define D_RECENT (1<<4)
  84. #define D_DRAFT (1<<5)
  85. #define D_MAX 6
  86. struct message
  87. {
  88. char *file;
  89. unsigned int uid;
  90. unsigned int flags;
  91. unsigned int size;
  92. message_t *next;
  93. unsigned int processed:1; /* message has already been evaluated */
  94. unsigned int new:1; /* message is in the new/ subdir */
  95. unsigned int changed:1; /* flags changed */
  96. unsigned int dead:1; /* message doesn't exist on the server */
  97. };
  98. /* struct used for parsing IMAP lists */
  99. typedef struct _list list_t;
  100. #define NIL (void*)0x1
  101. #define LIST (void*)0x2
  102. struct _list {
  103. char *val;
  104. list_t *next;
  105. list_t *child;
  106. };
  107. /* imap connection info */
  108. typedef struct
  109. {
  110. Socket_t *sock;
  111. unsigned int count; /* # of msgs */
  112. unsigned int recent; /* # of recent messages */
  113. buffer_t *buf; /* input buffer for reading server output */
  114. message_t *msgs; /* list of messages on the server */
  115. config_t *box; /* mailbox to open */
  116. char *prefix; /* namespace prefix */
  117. unsigned int deleted; /* # of deleted messages */
  118. unsigned int uidvalidity;
  119. unsigned int maxuid;
  120. unsigned int minuid;
  121. /* NAMESPACE info */
  122. list_t *ns_personal;
  123. list_t *ns_other;
  124. list_t *ns_shared;
  125. unsigned int have_namespace:1;
  126. #if HAVE_LIBSSL
  127. unsigned int have_cram:1;
  128. unsigned int have_starttls:1;
  129. unsigned int cram:1;
  130. #endif
  131. }
  132. imap_t;
  133. /* flags for sync_mailbox */
  134. #define SYNC_DELETE (1<<0) /* delete local that don't exist on server */
  135. #define SYNC_EXPUNGE (1<<1) /* don't fetch deleted messages */
  136. extern config_t global;
  137. extern unsigned int Tag;
  138. extern char Hostname[256];
  139. extern int Verbose;
  140. #if HAVE_LIBSSL
  141. extern SSL_CTX *SSLContext;
  142. char *cram (const char *, const char *, const char *);
  143. #endif
  144. char *next_arg (char **);
  145. int sync_mailbox (mailbox_t *, imap_t *, int, unsigned int);
  146. void config_defaults (config_t *);
  147. void load_config (const char *);
  148. config_t *find_box (const char *);
  149. void imap_close (imap_t *);
  150. int imap_copy_message (imap_t * imap, unsigned int uid, const char *mailbox);
  151. int imap_fetch_message (imap_t *, unsigned int, int);
  152. int imap_set_flags (imap_t *, unsigned int, unsigned int);
  153. int imap_expunge (imap_t *);
  154. imap_t *imap_open (config_t *, unsigned int, imap_t *);
  155. int imap_append_message (imap_t *, int, message_t *);
  156. mailbox_t *maildir_open (const char *, int fast);
  157. int maildir_expunge (mailbox_t *, int);
  158. int maildir_sync (mailbox_t *);
  159. int maildir_set_uidvalidity (mailbox_t *, unsigned int uidvalidity);
  160. void maildir_close (mailbox_t *);
  161. message_t * find_msg (message_t * list, unsigned int uid);
  162. void free_message (message_t *);
  163. /* parse an IMAP list construct */
  164. list_t * parse_list (char *s, char **end);
  165. int is_atom (list_t *list);
  166. int is_list (list_t *list);
  167. int is_nil (list_t *list);
  168. void free_list (list_t *list);
  169. #define strfcpy(a,b,c) {strncpy(a,b,c);(a)[c-1]=0;}