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 *command= "001 LOGOUT\r\n";
00045 const char *ok= "* OK";
00046 const char *bye= "* BYE";
00047
00048 if ( sock_recv(p->socket, buf, sizeof(buf), 0) <= 0 ) {
00049 log("IMAP: error receiving data -- %s\n", STRERROR);
00050 return FALSE;
00051 }
00052
00053 chomp(buf);
00054
00055 if ( strncasecmp(buf, ok, strlen(ok)) != 0 ) {
00056 log("IMAP error: %s\n", buf);
00057 return FALSE;
00058 }
00059
00060 if ( sock_send(p->socket, command, strlen(command), 0) < 0 ) {
00061 log("IMAP: error sending data -- %s\n", STRERROR);
00062 return FALSE;
00063 }
00064
00065 if ( sock_recv(p->socket, buf, sizeof(buf), 0) <= 0 ) {
00066 log("IMAP: error receiving data -- %s\n", STRERROR);
00067 return FALSE;
00068 }
00069
00070 chomp(buf);
00071
00072 if ( strncasecmp(buf, bye, strlen(bye)) != 0 ) {
00073 log("IMAP error: %s\n", buf);
00074 return FALSE;
00075 }
00076
00077 return TRUE;
00078
00079 }
00080