isync.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. /* imap connection info */
  87. typedef struct
  88. {
  89. Socket_t *sock;
  90. unsigned int count; /* # of msgs */
  91. unsigned int recent; /* # of recent messages */
  92. buffer_t *buf; /* input buffer for reading server output */
  93. message_t *msgs; /* list of messages on the server */
  94. config_t *box; /* mailbox to open */
  95. message_t *recent_msgs; /* list of recent messages - only contains
  96. * UID to be used in a FETCH FLAGS command
  97. */
  98. unsigned int deleted; /* # of deleted messages */
  99. }
  100. imap_t;
  101. /* flags for sync_mailbox */
  102. #define SYNC_FAST (1<<0) /* don't sync flags, only fetch new msgs */
  103. #define SYNC_DELETE (1<<1) /* delete local that don't exist on server */
  104. #define SYNC_EXPUNGE (1<<2) /* don't fetch deleted messages */
  105. extern config_t global;
  106. extern unsigned int Tag;
  107. extern char Hostname[256];
  108. extern int Verbose;
  109. #if HAVE_LIBSSL
  110. extern SSL_CTX *SSLContext;
  111. #endif
  112. char *next_arg (char **);
  113. int sync_mailbox (mailbox_t *, imap_t *, int);
  114. void imap_close (imap_t *);
  115. int imap_fetch_message (imap_t *, unsigned int, int);
  116. int imap_set_flags (imap_t *, unsigned int, unsigned int);
  117. int imap_expunge (imap_t *);
  118. imap_t *imap_open (config_t *, int);
  119. mailbox_t *maildir_open (const char *, int fast);
  120. int maildir_expunge (mailbox_t *, int);
  121. int maildir_sync (mailbox_t *);