| 367 | } |
| 368 | |
| 369 | int SmtpClient::smtpParse(char* buffer, size_t len) |
| 370 | { |
| 371 | char* start = buffer; |
| 372 | while(len) { |
| 373 | char currentByte = *buffer; |
| 374 | // parse the code... |
| 375 | if(codeLength < 3) { |
| 376 | code[codeLength++] = currentByte; |
| 377 | ADVANCE; |
| 378 | continue; |
| 379 | } |
| 380 | |
| 381 | if(codeLength == 3) { |
| 382 | code[codeLength] = '\0'; |
| 383 | if(currentByte != ' ' && currentByte != '-') { |
| 384 | // the code must be followed by space or minus |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | codeValue = strtol(code, nullptr, 10); |
| 389 | isLastLine = (currentByte == ' '); |
| 390 | codeLength++; |
| 391 | ADVANCE; |
| 392 | } |
| 393 | |
| 394 | char* line = buffer; |
| 395 | ADVANCE_UNTIL_EOL_OR_BREAK; |
| 396 | codeLength = 0; |
| 397 | int lineLength = (buffer - line) - 2; |
| 398 | |
| 399 | switch(state) { |
| 400 | case eSMTP_Banner: { |
| 401 | RETURN_ON_ERROR(SMTP_CODE_SERVICE_READY); |
| 402 | |
| 403 | if(!useSsl && (options & SMTP_OPT_STARTTLS)) { |
| 404 | if(!enableSsl(url.Host)) { |
| 405 | /* |
| 406 | * Excerpt from RFC 3207: If, |
| 407 | * after having issued the STARTTLS command, the client finds out that |
| 408 | * some failure prevents it from actually starting a TLS handshake, then |
| 409 | * it SHOULD abort the connection. |
| 410 | */ |
| 411 | return 0; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | sendString(F("EHLO ") + url.Host + "\r\n"); |
| 416 | state = eSMTP_Hello; |
| 417 | |
| 418 | break; |
| 419 | } |
| 420 | |
| 421 | case eSMTP_Hello: { |
| 422 | RETURN_ON_ERROR(SMTP_CODE_REQUEST_OK); |
| 423 | |
| 424 | if(strncmp(line, _F("PIPELINING"), lineLength) == 0) { |
| 425 | // PIPELINING (see: https://tools.ietf.org/html/rfc2920) |
| 426 | options |= SMTP_OPT_PIPELINE; |
nothing calls this directly
no test coverage detected