MCPcopy Create free account
hub / github.com/SmingHub/Sming / smtpParse

Method smtpParse

Sming/Components/Network/src/Network/SmtpClient.cpp:369–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369int 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;

Callers

nothing calls this directly

Calls 6

splitStringFunction · 0.85
minFunction · 0.85
FFunction · 0.50
base64_decodeFunction · 0.50
countMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected