isync.h 4.4 KB

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