Fossil SCM

Enhance the pop3 TOP command so that the second argument can be zero.

drh 2018-07-18 02:14 trunk
Commit 644931632362bd704b6ab2b24544039a3961f5835b0ed7b7159a5adc2f77394c
1 file changed +5 -5
+5 -5
--- src/smtp.c
+++ src/smtp.c
@@ -1487,32 +1487,32 @@
14871487
}
14881488
if( strcmp(zCmd,"retr")==0 || strcmp(zCmd,"top")==0 ){
14891489
Blob all, line;
14901490
int nLine = 0;
14911491
int iLimit;
1492
- int hdrSeen = 0;
1492
+ int hdrPending = 1;
14931493
if( zA1==0 ) goto cmd_error;
14941494
iLimit = zA2 ? atoi(zA2) : 2147483647;
1495
- if( iLimit<=0 ) goto cmd_error;
1495
+ if( iLimit<0 ) goto cmd_error;
14961496
z = db_text(0, "SELECT decompress(emailblob.etxt) "
14971497
" FROM emailblob, pop3"
14981498
" WHERE emailblob.emailid=pop3.emailid"
14991499
" AND pop3.id=%d AND NOT pop3.isDel",
15001500
atoi(zA1));
15011501
if( z==0 ) goto cmd_error;
15021502
pop3_print(pLog, "+OK");
15031503
blob_init(&all, z, -1);
1504
- while( iLimit && blob_line(&all, &line) ){
1504
+ while( (hdrPending || iLimit>0) && blob_line(&all, &line) ){
15051505
char c = blob_buffer(&line)[0];
15061506
if( c=='.' ){
15071507
fputc('.', stdout);
15081508
}else if( c=='\r' || c=='\n' ){
1509
- hdrSeen = 1;
1509
+ hdrPending = 0;
15101510
}
15111511
fwrite(blob_buffer(&line), 1, blob_size(&line), stdout);
15121512
nLine++;
1513
- if( hdrSeen ) iLimit--;
1513
+ if( !hdrPending ) iLimit--;
15141514
}
15151515
if( pLog ) fprintf(pLog, "S: # %d lines of content\n", nLine);
15161516
pop3_print(pLog, ".");
15171517
fossil_free(z);
15181518
blob_reset(&all);
15191519
--- src/smtp.c
+++ src/smtp.c
@@ -1487,32 +1487,32 @@
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);
1519
--- src/smtp.c
+++ src/smtp.c
@@ -1487,32 +1487,32 @@
1487 }
1488 if( strcmp(zCmd,"retr")==0 || strcmp(zCmd,"top")==0 ){
1489 Blob all, line;
1490 int nLine = 0;
1491 int iLimit;
1492 int hdrPending = 1;
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( (hdrPending || iLimit>0) && 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 hdrPending = 0;
1510 }
1511 fwrite(blob_buffer(&line), 1, blob_size(&line), stdout);
1512 nLine++;
1513 if( !hdrPending ) 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);
1519

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button