Skip to content
pop3.c 29.2 KiB
Newer Older
  /* Detect the end-of-body marker, which is 5 bytes:
     0d 0a 2e 0d 0a. This marker can of course be spread out
     over up to 5 different data chunks. Deal with it! */
  struct pop3_conn *pop3c = &conn->proto.pop3c;
  size_t checkmax = (nread >= POP3_EOB_LEN?POP3_EOB_LEN:nread);
  size_t checkleft = POP3_EOB_LEN-pop3c->eob;
  size_t check = (checkmax >= checkleft?checkleft:checkmax);

  if(!memcmp(POP3_EOB, &str[nread - check], check)) {
    /* substring match */
    pop3c->eob += check;
    if(pop3c->eob == POP3_EOB_LEN) {
      /* full match, the transfer is done! */
Yang Tse's avatar
 
Yang Tse committed
      str[nread - check] = '\0';
      nread -= check;
      k->keepon &= ~KEEP_RECV;
      pop3c->eob = 0;
    }
  }
  else if(pop3c->eob) {
    /* not a match, but we matched a piece before so we must now
       send that part as body first, before we move on and send
       this buffer */
    result = Curl_client_write(conn, CLIENTWRITE_BODY,
                               (char *)POP3_EOB, pop3c->eob);
    if(result)
      return result;
    pop3c->eob = 0;
  }

  result = Curl_client_write(conn, CLIENTWRITE_BODY, str, nread);

  return result;
}

#endif /* CURL_DISABLE_POP3 */