1 /* $Id: Client.h,v 1.42 2005/05/08 21:31:22 bluehal Exp $ */ 2 /* Author : Scott Holden ( scotth@thezone.net ) 3 Modified : Yong-iL Joh ( tolkien@mizi.com ) 4 Modified : Jorge Garc�a ( Jorge.Garcia@uv.es ) 5 * 6 * Email Checker Pop3/Imap4/Gicu/mbox/maildir/finger 7 * 8 * Last Updated : $Date: 2005/05/08 21:31:22 $ 9 * 10 */ 11 12 #ifndef CLIENT 13 #define CLIENT 14 15 #ifdef HAVE_CONFIG_H 16 #include <config.h> 17 #endif 18 19 #include <string.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <stdint.h> 23 #include <sys/time.h> 24 25 #ifdef HAVE_GCRYPT_H 26 #include <gcrypt.h> 27 #endif 28 29 #ifdef __LCLINT__ 30 typedef unsigned int off_t; 31 #endif 32 33 #define BUF_BIG 256 34 #define BUF_SMALL 32 35 #define BUF_SIZE 1024 36 37 struct msglst; 38 39 typedef struct Pop3_ { 40 char label[BUF_SMALL]; /* Printed at left; max 5 chars */ 41 char path[BUF_BIG]; /* Path to mailbox */ 42 char notify[BUF_BIG]; /* Program to notify mail arrivation */ 43 char action[BUF_BIG]; /* Action to execute on mouse click, reduces to 44 * what happens on button1. this is executed after 45 * either actionnew or actionnonew (if they are 46 * defined in the config file) */ 47 char actionnew[BUF_BIG]; /* Action to execute on mouse click when new mail */ 48 char actionnonew[BUF_BIG]; /* Action to execute on mouse click when no new mail */ 49 char actiondc[BUF_BIG]; /* Action to execute when icq is disconnected */ 50 char button2[BUF_BIG]; /* What to run on button2. (middle) */ 51 char fetchcmd[BUF_BIG]; /* Action for mail fetching for pop3/imap, reduces to what happens on button3 */ 52 int fetchinterval; 53 int TotalMsgs; /* Total messages in mailbox */ 54 int UnreadMsgs; /* New (unread) messages in mailbox */ 55 int OldMsgs; 56 int OldUnreadMsgs; 57 char TextStatus[10]; /* if set to a string, toupper() and blit 58 * that string. instead of a message count */ 59 int blink_stat; /* blink digits flag-counter */ 60 int debug; /* debugging status */ 61 62 struct msglst *headerCache; 63 64 union { 65 struct { 66 time_t mtime; 67 off_t size; 68 } mbox; 69 struct { 70 char *detail; 71 } shell; 72 struct { 73 time_t mtime_new; 74 off_t size_new; 75 time_t mtime_cur; 76 off_t size_cur; 77 unsigned int dircache_flush:1; /* hack to flush directory caches */ 78 } maildir; 79 struct { 80 char password[BUF_SMALL]; 81 char userName[BUF_BIG]; 82 char serverName[BUF_BIG]; 83 uint16_t serverPort; 84 uint16_t localPort; 85 char authList[100]; 86 unsigned int dossl:1; /* use tls. */ 87 /* prompt the user if we can't login / password is empty */ 88 unsigned int interactive_password:1; 89 /* using the msglst feature, fetch the headers 90 to have them on hand */ 91 unsigned int wantCacheHeaders:1; 92 size_t password_len; /* memfrob may shorten passwords */ 93 } pop_imap; 94 } u; 95 96 int (*checkMail) ( /*@notnull@ */ struct Pop3_ *); 97 98 /* collect the headers to show in a pop up */ 99 struct msglst *(*getHeaders) ( /*@notnull@ */ struct Pop3_ *); 100 /* allow the client to free the headers, or keep them cached */ 101 void (*releaseHeaders) ( /*@notnull@ */ struct Pop3_ *, struct msglst * ml); 102 103 time_t prevtime; 104 time_t prevfetch_time; 105 int loopinterval; /* loop interval for this mailbox */ 106 107 /* command to execute to get a password, if needed */ 108 const char *askpass; 109 } Pop3; 110 111 /* creation calls must have this prototype */ 112 int pop3Create( /*@notnull@ */ Pop3 *pc, const char *str); 113 int imap4Create( /*@notnull@ */ Pop3 *pc, const char *str); 114 int shellCreate( /*@notnull@ */ Pop3 *pc, const char *str); 115 int mboxCreate( /*@notnull@ */ Pop3 *pc, const char *str); 116 int maildirCreate( /*@notnull@ */ Pop3 *pc, const char *str); 117 118 int sock_connect(const char *hostname, uint16_t port); 119 FILE *openMailbox(Pop3 *pc, const char *mbox_filename); 120 121 /* backtickExpand returns null on failure */ 122 /*@null@ */ 123 char *backtickExpand(Pop3 *pc, const char *path); 124 int fileHasChanged(const char *mbox_filename, time_t * atime, 125 time_t * mtime, off_t * size); 126 int grabCommandOutput(Pop3 *pc, const char *command, 127 /*@out@ */ char **output, 128 /*@out@ *//*@null@ */ char **details); 129 int exists(const char *filename); /* test -f */ 130 131 /* _NONE is for silent operation. _ERROR is for things that should 132 be printed assuming that the user might possibly see them. _INFO is 133 for reasonably useless but possibly interesting messages. _ALL is 134 for everything. Restated, _ERROR will always be printed, _INFO only 135 if debugging messages were requested. */ 136 #define DEBUG_NONE 0 137 #define DEBUG_ERROR 1 138 #define DEBUG_INFO 2 139 #define DEBUG_ALL 2 140 /* inspired by ksymoops-2.3.4/ksymoops.h */ 141 #define DM(mbox, msglevel, X...) \ 142 do { \ 143 if (mbox == NULL || (mbox)->debug >= msglevel) { \ 144 printf("wmbiff/%s ", (mbox != NULL) ? (mbox)->label : "NULL"); \ 145 printf(X); \ 146 (void)fflush(NULL); \ 147 } \ 148 } while(0) 149 150 extern int debug_default; 151 #define DMA(msglevel, X...) \ 152 do { \ 153 if (debug_default >= msglevel) { \ 154 printf("wmbiff: " X); \ 155 (void)fflush(NULL); \ 156 } \ 157 } while(0) 158 159 /* technique used in apache to allow GCC's attribute tags, 160 without requiring gcc as the compiler */ 161 #if !defined(__GNUC__) || __GNUC__ < 2 || \ 162 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 163 #ifndef __attribute__ 164 #define __attribute__(__x) 165 #endif 166 #endif /* gnuc */ 167 #endif /* client.h */ 168 169 #ifndef FALSE 170 #define FALSE (0) 171 #define TRUE (!FALSE) 172 #endif 173 174 #ifdef __LCLINT__ 175 /* lclint doesn't do typeof */ 176 #define min(x,y) ((x > y) ? x : y) 177 #define max(x,y) ((x > y) ? x : y) 178 #else 179 /* from linux/kernel.h */ 180 #define min(x,y) ({ \ 181 const typeof(x) _xi = (x); \ 182 const typeof(y) _yi = (y); \ 183 (void) (&_xi == &_yi); \ 184 _xi < _yi ? _xi : _yi; }) 185 #define max(x,y) ({ \ 186 const typeof(x) _xa = (x); \ 187 const typeof(y) _ya = (y); \ 188 (void) (&_xa == &_ya); \ 189 _xa > _ya ? _xa : _ya; }) 190 #endif 191 192 193 /* vim:set ts=4: */ 194 /* 195 * Local Variables: 196 * tab-width: 4 197 * c-indent-level: 4 198 * c-basic-offset: 4 199 * End: 200 */ 201