00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <stdio.h>
00023 #include <errno.h>
00024
00025 #ifdef HAVE_STRING_H
00026 #include <string.h>
00027 #endif
00028
00029 #include "protocol.h"
00030
00041 int check_imap(Port_T p) {
00042
00043 char buf[STRLEN];
00044 const char *ok= "* OK";
00045 const char *bye= "* BYE";
00046 const char *command= "001 LOGOUT\r\n";
00047
00048 ASSERT(p);
00049
00050 if(port_recv(p, buf, sizeof(buf), 0) <= 0) {
00051 log("IMAP: error receiving data -- %s\n", STRERROR);
00052 return FALSE;
00053 }
00054
00055 chomp(buf);
00056
00057 if(strncasecmp(buf, ok, strlen(ok)) != 0) {
00058 log("IMAP error: %s\n", buf);
00059 return FALSE;
00060 }
00061
00062 if(port_send(p, command, strlen(command), 0) < 0) {
00063 log("IMAP: error sending data -- %s\n", STRERROR);
00064 return FALSE;
00065 }
00066
00067 if(port_recv(p, buf, sizeof(buf), 0) <= 0) {
00068 log("IMAP: error receiving data -- %s\n", STRERROR);
00069 return FALSE;
00070 }
00071
00072 chomp(buf);
00073
00074 if(strncasecmp(buf, bye, strlen(bye)) != 0) {
00075 log("IMAP error: %s\n", buf);
00076 return FALSE;
00077 }
00078
00079 return TRUE;
00080
00081 }
00082