isync.h 3.9 KB

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