- int len;
- char *token;
- char *stringp;
-
- /* All interactions transmitted by client and server are in the form of
- lines, that is, strings that end with a CRLF. The protocol receiver
- of an IMAP4rev1 client or server is either reading a line, or is
- reading a sequence of octets with a known count followed by a line. */
-
- get_packet:
- len = WmnotifyGetResponse( rx_buffer, WMNOTIFY_BUFSIZE );
- if( len < 0 ) {
- /* An error occured. WmnotifyGetResponse() should have printed an error message. */
- goto error;
- }
- else if( len == 0 ) {
- /* The return value will be 0 when the peer has performed an orderly shutdown. */
- if( wmnotify_infos.debug ) {
- fprintf( stderr, "IMAP server has closed connection.\n" );
- }
- goto error;
- }
- else if( len == WMNOTIFY_BUFSIZE ) {
- if( wmnotify_infos.debug ) {
- ErrorLocation( __FILE__, __LINE__ );
- fprintf( stderr, "Response too big (%d bytes) to fit in receive buffer.\n", len );
- }
- goto error;
- }
-
- /* We suppose that, if a partial response packet was sent, it is not broken in the middle
- of a line (to confirm). Normally, each string is terminated by CRLF. */
- if( STREQ_LEN( &rx_buffer[ len - 2 ], IMAP4_ENDL, 2 ) == false ) {
- /* No CRLF found at the end of the buffer --> not handled by wmnotify. */
- ErrorLocation( __FILE__, __LINE__ );
- fprintf( stderr, "Response buffer doesn't contain CRLF at the end.\n" );
- goto error;
- }
-
- if( wmnotify_infos.debug ) {
- printf( "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" );
- printf( "IMAP4 Server Response (size %d bytes):\n", len );
- printf( "%s", rx_buffer );
- printf( "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n" );
- }
-
- /* Converting the last CRLF into a LF followed by a NULL termination character. */
- rx_buffer[ len - 2 ] = '\n';
- rx_buffer[ len - 1 ] = '\0';
-
- /* Check the Server Completion Response returned by the IMAP4 server. There are currently
- * three Server Completion Responses codes: success ("OK"), failure ("NO") and protocol error
- * ("BAD"). */
- stringp = rx_buffer;
-
- while( ( token = strsep( &stringp, "\n" ) ) != NULL ) {
-
- /* In case no delimiter was found, the token is taken to
- be the entire string *stringp, and *stringp is made NULL. */
- if( stringp == NULL ) {
- if( token[0] == '\0' ) {
- /* This means we finished parsing the last line of the buffer, but we need to
- get more data to continue process the next part of the IMAP4 response. */
- goto get_packet;
- }
- else {
- /* This should never happen. */
- ErrorLocation( __FILE__, __LINE__ );
- fprintf( stderr, " Delimiter not found in strsep() call.\n" );
- goto error;
- }
- }
-
- if( token == NULL ) {
- /* This should never happen. */
- ErrorLocation( __FILE__, __LINE__ );
- fprintf( stderr, " NULL token returned by strsep().\n" );
- goto error;
- }
-
- if( token[0] == '*' ) {
- /* Untagged response. If there is a space after the SEARCH response, it means
- * at least 1 message is unseen. */
- if( STREQ_LEN( token, IMAP4_RSP_SEARCH_UNSEEN, strlen(IMAP4_RSP_SEARCH_UNSEEN) ) == true ) {
- unseen_string_found = true;
- }
- }
- else {
- /* Must be the status... */
-
- /* We check for the correct transaction label plus a space. */
- if( STREQ_LEN( token, tx_buffer, tlabel_len + 1 ) == true ) {
- token += tlabel_len + 1;
- if( STREQ_LEN( token, IMAP4_RSP_SUCCESS, strlen(IMAP4_RSP_SUCCESS) ) == true ) {
- goto end; /* OK, no errors. */
+ int len;
+ char *token;
+ char *stringp;
+
+ /*
+ * All interactions transmitted by client and server are in the form of
+ * lines, that is, strings that end with a CRLF. The protocol receiver
+ * of an IMAP4rev1 client or server is either reading a line, or is
+ * reading a sequence of octets with a known count followed by a line.
+ */
+
+get_packet:
+ len = WmnotifyGetResponse(rx_buffer, WMNOTIFY_BUFSIZE);
+ if (len < 0) {
+ /*
+ * An error occured. WmnotifyGetResponse() should have printed
+ * an error message.
+ */
+ goto error;
+ } else if (len == 0) {
+ /*
+ * The return value will be 0 when the peer has performed an
+ * orderly shutdown.
+ */
+ if (wmnotify_infos.debug) {
+ fprintf(stderr,
+ "IMAP server has closed connection.\n");
+ }
+ goto error;
+ } else if (len == WMNOTIFY_BUFSIZE) {
+ if (wmnotify_infos.debug) {
+ ErrorLocation(__FILE__, __LINE__);
+ fprintf(stderr,
+ "Response too big (%d bytes) to fit in receive buffer.\n",
+ len);
+ }
+ goto error;