Fossil SCM
Add support for TOP and CAPA to pop3d.
Commit
2c18ed076e008633641ff49d4ca0e1787f04496b3273307eeb66724a750a51d0
Parent
2332efb74a214db…
1 file changed
+24
-7
+24
-7
| --- src/smtp.c | ||
| +++ src/smtp.c | ||
| @@ -1373,11 +1373,11 @@ | ||
| 1373 | 1373 | void pop3d_command(void){ |
| 1374 | 1374 | char *zDbName; |
| 1375 | 1375 | char *zA1, *zA2, *zCmd, *z; |
| 1376 | 1376 | int inAuth = 1; |
| 1377 | 1377 | int i; |
| 1378 | - FILE *pLog; | |
| 1378 | + FILE *pLog = 0; | |
| 1379 | 1379 | const char *zDir; |
| 1380 | 1380 | Stmt q; |
| 1381 | 1381 | char zIn[1000]; |
| 1382 | 1382 | char zUser[100]; |
| 1383 | 1383 | zDir = find_option("logdir",0,1); |
| @@ -1397,10 +1397,22 @@ | ||
| 1397 | 1397 | if( pLog ) fprintf(pLog, "C: %s", zIn); |
| 1398 | 1398 | zCmd = zIn; |
| 1399 | 1399 | zA1 = pop3d_arg(zCmd); |
| 1400 | 1400 | zA2 = zA1 ? pop3d_arg(zA1) : 0; |
| 1401 | 1401 | for(i=0; zCmd[i]; i++){ zCmd[i] = fossil_tolower(zCmd[i]); } |
| 1402 | + if( strcmp(zCmd,"capa")==0 ){ | |
| 1403 | + static const char *azCap[] = { | |
| 1404 | + "TOP", "USER", "UIDL", | |
| 1405 | + }; | |
| 1406 | + int i; | |
| 1407 | + pop3_print(pLog, "+OK"); | |
| 1408 | + for(i=0; i<sizeof(azCap)/sizeof(azCap[0]); i++){ | |
| 1409 | + pop3_print(pLog, azCap[i]); | |
| 1410 | + } | |
| 1411 | + pop3_print(pLog, "."); | |
| 1412 | + continue; | |
| 1413 | + } | |
| 1402 | 1414 | if( inAuth ){ |
| 1403 | 1415 | if( strcmp(zCmd,"user")==0 ){ |
| 1404 | 1416 | if( zA1==0 || zA2!=0 ) goto cmd_error; |
| 1405 | 1417 | sqlite3_snprintf(sizeof(zUser),zUser,"%s",zA1); |
| 1406 | 1418 | goto cmd_ok; |
| @@ -1471,28 +1483,36 @@ | ||
| 1471 | 1483 | pop3_print(pLog, "."); |
| 1472 | 1484 | } |
| 1473 | 1485 | db_finalize(&q); |
| 1474 | 1486 | continue; |
| 1475 | 1487 | } |
| 1476 | - if( strcmp(zCmd,"retr")==0 ){ | |
| 1488 | + if( strcmp(zCmd,"retr")==0 || strcmp(zCmd,"top")==0 ){ | |
| 1477 | 1489 | Blob all, line; |
| 1478 | 1490 | int nLine = 0; |
| 1491 | + int iLimit; | |
| 1492 | + int hdrSeen = 0; | |
| 1479 | 1493 | if( zA1==0 ) goto cmd_error; |
| 1494 | + iLimit = zA2 ? atoi(zA2) : 2147483647; | |
| 1495 | + if( iLimit<=0 ) goto cmd_error; | |
| 1480 | 1496 | z = db_text(0, "SELECT decompress(emailblob.etxt) " |
| 1481 | 1497 | " FROM emailblob, pop3" |
| 1482 | 1498 | " WHERE emailblob.emailid=pop3.emailid" |
| 1483 | 1499 | " AND pop3.id=%d AND NOT pop3.isDel", |
| 1484 | 1500 | atoi(zA1)); |
| 1485 | 1501 | if( z==0 ) goto cmd_error; |
| 1486 | 1502 | pop3_print(pLog, "+OK"); |
| 1487 | 1503 | blob_init(&all, z, -1); |
| 1488 | - while( blob_line(&all, &line) ){ | |
| 1489 | - if( blob_buffer(&line)[0]=='.' ){ | |
| 1504 | + while( iLimit && blob_line(&all, &line) ){ | |
| 1505 | + char c = blob_buffer(&line)[0]; | |
| 1506 | + if( c=='.' ){ | |
| 1490 | 1507 | fputc('.', stdout); |
| 1508 | + }else if( c=='\r' || c=='\n' ){ | |
| 1509 | + hdrSeen = 1; | |
| 1491 | 1510 | } |
| 1492 | 1511 | fwrite(blob_buffer(&line), 1, blob_size(&line), stdout); |
| 1493 | 1512 | nLine++; |
| 1513 | + if( hdrSeen ) iLimit--; | |
| 1494 | 1514 | } |
| 1495 | 1515 | if( pLog ) fprintf(pLog, "S: # %d lines of content\n", nLine); |
| 1496 | 1516 | pop3_print(pLog, "."); |
| 1497 | 1517 | fossil_free(z); |
| 1498 | 1518 | blob_reset(&all); |
| @@ -1507,13 +1527,10 @@ | ||
| 1507 | 1527 | } |
| 1508 | 1528 | if( strcmp(zCmd,"rset")==0 ){ |
| 1509 | 1529 | db_multi_exec("UPDATE pop3 SET isDel=0"); |
| 1510 | 1530 | goto cmd_ok; |
| 1511 | 1531 | } |
| 1512 | - if( strcmp(zCmd,"top")==0 ){ | |
| 1513 | - goto cmd_error; | |
| 1514 | - } | |
| 1515 | 1532 | if( strcmp(zCmd,"uidl")==0 ){ |
| 1516 | 1533 | if( zA1 ){ |
| 1517 | 1534 | db_prepare(&q, "SELECT id, emailid FROM pop3" |
| 1518 | 1535 | " WHERE id=%d AND NOT isDel", atoi(zA1)); |
| 1519 | 1536 | if( db_step(&q)==SQLITE_ROW ){ |
| 1520 | 1537 |
| --- src/smtp.c | |
| +++ src/smtp.c | |
| @@ -1373,11 +1373,11 @@ | |
| 1373 | void pop3d_command(void){ |
| 1374 | char *zDbName; |
| 1375 | char *zA1, *zA2, *zCmd, *z; |
| 1376 | int inAuth = 1; |
| 1377 | int i; |
| 1378 | FILE *pLog; |
| 1379 | const char *zDir; |
| 1380 | Stmt q; |
| 1381 | char zIn[1000]; |
| 1382 | char zUser[100]; |
| 1383 | zDir = find_option("logdir",0,1); |
| @@ -1397,10 +1397,22 @@ | |
| 1397 | if( pLog ) fprintf(pLog, "C: %s", zIn); |
| 1398 | zCmd = zIn; |
| 1399 | zA1 = pop3d_arg(zCmd); |
| 1400 | zA2 = zA1 ? pop3d_arg(zA1) : 0; |
| 1401 | for(i=0; zCmd[i]; i++){ zCmd[i] = fossil_tolower(zCmd[i]); } |
| 1402 | if( inAuth ){ |
| 1403 | if( strcmp(zCmd,"user")==0 ){ |
| 1404 | if( zA1==0 || zA2!=0 ) goto cmd_error; |
| 1405 | sqlite3_snprintf(sizeof(zUser),zUser,"%s",zA1); |
| 1406 | goto cmd_ok; |
| @@ -1471,28 +1483,36 @@ | |
| 1471 | pop3_print(pLog, "."); |
| 1472 | } |
| 1473 | db_finalize(&q); |
| 1474 | continue; |
| 1475 | } |
| 1476 | if( strcmp(zCmd,"retr")==0 ){ |
| 1477 | Blob all, line; |
| 1478 | int nLine = 0; |
| 1479 | if( zA1==0 ) goto cmd_error; |
| 1480 | z = db_text(0, "SELECT decompress(emailblob.etxt) " |
| 1481 | " FROM emailblob, pop3" |
| 1482 | " WHERE emailblob.emailid=pop3.emailid" |
| 1483 | " AND pop3.id=%d AND NOT pop3.isDel", |
| 1484 | atoi(zA1)); |
| 1485 | if( z==0 ) goto cmd_error; |
| 1486 | pop3_print(pLog, "+OK"); |
| 1487 | blob_init(&all, z, -1); |
| 1488 | while( blob_line(&all, &line) ){ |
| 1489 | if( blob_buffer(&line)[0]=='.' ){ |
| 1490 | fputc('.', stdout); |
| 1491 | } |
| 1492 | fwrite(blob_buffer(&line), 1, blob_size(&line), stdout); |
| 1493 | nLine++; |
| 1494 | } |
| 1495 | if( pLog ) fprintf(pLog, "S: # %d lines of content\n", nLine); |
| 1496 | pop3_print(pLog, "."); |
| 1497 | fossil_free(z); |
| 1498 | blob_reset(&all); |
| @@ -1507,13 +1527,10 @@ | |
| 1507 | } |
| 1508 | if( strcmp(zCmd,"rset")==0 ){ |
| 1509 | db_multi_exec("UPDATE pop3 SET isDel=0"); |
| 1510 | goto cmd_ok; |
| 1511 | } |
| 1512 | if( strcmp(zCmd,"top")==0 ){ |
| 1513 | goto cmd_error; |
| 1514 | } |
| 1515 | if( strcmp(zCmd,"uidl")==0 ){ |
| 1516 | if( zA1 ){ |
| 1517 | db_prepare(&q, "SELECT id, emailid FROM pop3" |
| 1518 | " WHERE id=%d AND NOT isDel", atoi(zA1)); |
| 1519 | if( db_step(&q)==SQLITE_ROW ){ |
| 1520 |
| --- src/smtp.c | |
| +++ src/smtp.c | |
| @@ -1373,11 +1373,11 @@ | |
| 1373 | void pop3d_command(void){ |
| 1374 | char *zDbName; |
| 1375 | char *zA1, *zA2, *zCmd, *z; |
| 1376 | int inAuth = 1; |
| 1377 | int i; |
| 1378 | FILE *pLog = 0; |
| 1379 | const char *zDir; |
| 1380 | Stmt q; |
| 1381 | char zIn[1000]; |
| 1382 | char zUser[100]; |
| 1383 | zDir = find_option("logdir",0,1); |
| @@ -1397,10 +1397,22 @@ | |
| 1397 | if( pLog ) fprintf(pLog, "C: %s", zIn); |
| 1398 | zCmd = zIn; |
| 1399 | zA1 = pop3d_arg(zCmd); |
| 1400 | zA2 = zA1 ? pop3d_arg(zA1) : 0; |
| 1401 | for(i=0; zCmd[i]; i++){ zCmd[i] = fossil_tolower(zCmd[i]); } |
| 1402 | if( strcmp(zCmd,"capa")==0 ){ |
| 1403 | static const char *azCap[] = { |
| 1404 | "TOP", "USER", "UIDL", |
| 1405 | }; |
| 1406 | int i; |
| 1407 | pop3_print(pLog, "+OK"); |
| 1408 | for(i=0; i<sizeof(azCap)/sizeof(azCap[0]); i++){ |
| 1409 | pop3_print(pLog, azCap[i]); |
| 1410 | } |
| 1411 | pop3_print(pLog, "."); |
| 1412 | continue; |
| 1413 | } |
| 1414 | if( inAuth ){ |
| 1415 | if( strcmp(zCmd,"user")==0 ){ |
| 1416 | if( zA1==0 || zA2!=0 ) goto cmd_error; |
| 1417 | sqlite3_snprintf(sizeof(zUser),zUser,"%s",zA1); |
| 1418 | goto cmd_ok; |
| @@ -1471,28 +1483,36 @@ | |
| 1483 | pop3_print(pLog, "."); |
| 1484 | } |
| 1485 | db_finalize(&q); |
| 1486 | continue; |
| 1487 | } |
| 1488 | if( strcmp(zCmd,"retr")==0 || strcmp(zCmd,"top")==0 ){ |
| 1489 | Blob all, line; |
| 1490 | int nLine = 0; |
| 1491 | int iLimit; |
| 1492 | int hdrSeen = 0; |
| 1493 | if( zA1==0 ) goto cmd_error; |
| 1494 | iLimit = zA2 ? atoi(zA2) : 2147483647; |
| 1495 | if( iLimit<=0 ) goto cmd_error; |
| 1496 | z = db_text(0, "SELECT decompress(emailblob.etxt) " |
| 1497 | " FROM emailblob, pop3" |
| 1498 | " WHERE emailblob.emailid=pop3.emailid" |
| 1499 | " AND pop3.id=%d AND NOT pop3.isDel", |
| 1500 | atoi(zA1)); |
| 1501 | if( z==0 ) goto cmd_error; |
| 1502 | pop3_print(pLog, "+OK"); |
| 1503 | blob_init(&all, z, -1); |
| 1504 | while( iLimit && blob_line(&all, &line) ){ |
| 1505 | char c = blob_buffer(&line)[0]; |
| 1506 | if( c=='.' ){ |
| 1507 | fputc('.', stdout); |
| 1508 | }else if( c=='\r' || c=='\n' ){ |
| 1509 | hdrSeen = 1; |
| 1510 | } |
| 1511 | fwrite(blob_buffer(&line), 1, blob_size(&line), stdout); |
| 1512 | nLine++; |
| 1513 | if( hdrSeen ) iLimit--; |
| 1514 | } |
| 1515 | if( pLog ) fprintf(pLog, "S: # %d lines of content\n", nLine); |
| 1516 | pop3_print(pLog, "."); |
| 1517 | fossil_free(z); |
| 1518 | blob_reset(&all); |
| @@ -1507,13 +1527,10 @@ | |
| 1527 | } |
| 1528 | if( strcmp(zCmd,"rset")==0 ){ |
| 1529 | db_multi_exec("UPDATE pop3 SET isDel=0"); |
| 1530 | goto cmd_ok; |
| 1531 | } |
| 1532 | if( strcmp(zCmd,"uidl")==0 ){ |
| 1533 | if( zA1 ){ |
| 1534 | db_prepare(&q, "SELECT id, emailid FROM pop3" |
| 1535 | " WHERE id=%d AND NOT isDel", atoi(zA1)); |
| 1536 | if( db_step(&q)==SQLITE_ROW ){ |
| 1537 |