isync.h 5.4 KB

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