isync.h 5.6 KB

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