isync.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <sys/types.h>
  21. #include <stdarg.h>
  22. #if HAVE_LIBSSL
  23. #include <openssl/ssl.h>
  24. #endif
  25. typedef struct
  26. {
  27. int fd;
  28. #if HAVE_LIBSSL
  29. SSL *ssl;
  30. unsigned int use_ssl:1;
  31. #endif
  32. } Socket_t;
  33. typedef struct
  34. {
  35. Socket_t *sock;
  36. char buf[1024];
  37. int bytes;
  38. int offset;
  39. }
  40. buffer_t;
  41. typedef struct config config_t;
  42. typedef struct mailbox mailbox_t;
  43. typedef struct message message_t;
  44. struct config
  45. {
  46. char *maildir;
  47. char *path; /* path relative to .maildir, or absolute path */
  48. char *host;
  49. int port;
  50. char *user;
  51. char *pass;
  52. char *box;
  53. char *alias;
  54. char *copy_deleted_to;
  55. unsigned int max_messages;
  56. off_t max_size;
  57. config_t *next;
  58. #if HAVE_LIBSSL
  59. char *cert_file;
  60. unsigned int use_imaps:1;
  61. unsigned int require_ssl:1;
  62. unsigned int use_sslv2:1;
  63. unsigned int use_sslv3:1;
  64. unsigned int use_tlsv1:1;
  65. unsigned int require_cram:1;
  66. #endif
  67. unsigned int use_namespace:1;
  68. unsigned int expunge:1;
  69. unsigned int delete:1;
  70. unsigned int wanted:1;
  71. };
  72. /* struct representing local mailbox file */
  73. struct mailbox
  74. {
  75. char *path;
  76. message_t *msgs;
  77. unsigned int deleted; /* # of deleted messages */
  78. unsigned int uidvalidity;
  79. unsigned int maxuid; /* largest uid we know about */
  80. unsigned int changed:1;
  81. unsigned int maxuidchanged:1;
  82. };
  83. /* message dispositions */
  84. #define D_SEEN (1<<0)
  85. #define D_ANSWERED (1<<1)
  86. #define D_DELETED (1<<2)
  87. #define D_FLAGGED (1<<3)
  88. #define D_RECENT (1<<4)
  89. #define D_DRAFT (1<<5)
  90. #define D_MAX 6
  91. struct message
  92. {
  93. char *file;
  94. unsigned int uid;
  95. unsigned int flags;
  96. size_t size;
  97. message_t *next;
  98. unsigned int processed:1; /* message has already been evaluated */
  99. unsigned int new:1; /* message is in the new/ subdir */
  100. unsigned int changed:1; /* flags changed */
  101. unsigned int dead:1; /* message doesn't exist on the server */
  102. unsigned int wanted:1; /* when using MaxMessages, keep this message */
  103. };
  104. /* struct used for parsing IMAP lists */
  105. typedef struct _list list_t;
  106. #define NIL (void*)0x1
  107. #define LIST (void*)0x2
  108. struct _list {
  109. char *val;
  110. list_t *next;
  111. list_t *child;
  112. };
  113. /* imap connection info */
  114. typedef struct
  115. {
  116. Socket_t *sock;
  117. unsigned int count; /* # of msgs */
  118. unsigned int recent; /* # of recent messages */
  119. buffer_t *buf; /* input buffer for reading server output */
  120. message_t *msgs; /* list of messages on the server */
  121. config_t *box; /* mailbox to open */
  122. char *prefix; /* namespace prefix */
  123. unsigned int deleted; /* # of deleted messages */
  124. unsigned int uidvalidity;
  125. unsigned int maxuid;
  126. unsigned int minuid;
  127. /* NAMESPACE info */
  128. list_t *ns_personal;
  129. list_t *ns_other;
  130. list_t *ns_shared;
  131. unsigned int have_namespace:1;
  132. #if HAVE_LIBSSL
  133. unsigned int have_cram:1;
  134. unsigned int have_starttls:1;
  135. unsigned int cram:1;
  136. #endif
  137. }
  138. imap_t;
  139. /* flags for sync_mailbox */
  140. #define SYNC_DELETE (1<<0) /* delete local that don't exist on server */
  141. #define SYNC_EXPUNGE (1<<1) /* don't fetch deleted messages */
  142. #define SYNC_QUIET (1<<2) /* only display critical errors */
  143. extern config_t global;
  144. extern config_t *boxes;
  145. extern unsigned int Tag;
  146. extern char Hostname[256];
  147. extern int Verbose;
  148. #if HAVE_LIBSSL
  149. extern SSL_CTX *SSLContext;
  150. char *cram (const char *, const char *, const char *);
  151. #endif
  152. char *next_arg (char **);
  153. int sync_mailbox (mailbox_t *, imap_t *, int, unsigned int, unsigned int);
  154. void load_config (const char *);
  155. char * expand_strdup (const char *s);
  156. config_t *find_box (const char *);
  157. void imap_close (imap_t *);
  158. int imap_copy_message (imap_t * imap, unsigned int uid, const char *mailbox);
  159. int imap_fetch_message (imap_t *, unsigned int, int);
  160. int imap_set_flags (imap_t *, unsigned int, unsigned int);
  161. int imap_expunge (imap_t *);
  162. imap_t *imap_open (config_t *, unsigned int, imap_t *);
  163. int imap_append_message (imap_t *, int, message_t *);
  164. mailbox_t *maildir_open (const char *, int fast);
  165. int maildir_expunge (mailbox_t *, int);
  166. int maildir_set_uidvalidity (mailbox_t *, unsigned int uidvalidity);
  167. int maildir_close (mailbox_t *);
  168. message_t * find_msg (message_t * list, unsigned int uid);
  169. void free_message (message_t *);
  170. /* parse an IMAP list construct */
  171. list_t * parse_list (char *s, char **end);
  172. int is_atom (list_t *list);
  173. int is_list (list_t *list);
  174. int is_nil (list_t *list);
  175. void free_list (list_t *list);
  176. #define strfcpy(a,b,c) {strncpy(a,b,c);(a)[c-1]=0;}