Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Use the email content parser to the prototype webmail page. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
264223fc5981cd27b255e5f4170c2a81 |
User & Date: | drh 2018-07-13 15:07:13.307 |
Context
2018-07-13
| ||
16:06 | When rendering SQLite log messages to the error log, include the SQL for all busy SQL statements in the log message. ... (check-in: c6ecf21f user: drh tags: trunk) | |
15:07 | Use the email content parser to the prototype webmail page. ... (check-in: 264223fc user: drh tags: trunk) | |
10:04 | Append -ldl only when needed on the target platform; OpenBSD resolves it from the standard libc. ... (check-in: 7cdb522b user: ashepilko tags: trunk) | |
Changes
Changes to src/db.c.
︙ | ︙ | |||
517 518 519 520 521 522 523 524 525 526 527 528 529 530 | } char *db_column_malloc(Stmt *pStmt, int N){ return mprintf("%s", db_column_text(pStmt, N)); } void db_column_blob(Stmt *pStmt, int N, Blob *pBlob){ blob_append(pBlob, sqlite3_column_blob(pStmt->pStmt, N), sqlite3_column_bytes(pStmt->pStmt, N)); } /* ** Initialize a blob to an ephemeral copy of the content of a ** column in the current row. The data in the blob will become ** invalid when the statement is stepped or reset. */ | > > > > > > | 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | } char *db_column_malloc(Stmt *pStmt, int N){ return mprintf("%s", db_column_text(pStmt, N)); } void db_column_blob(Stmt *pStmt, int N, Blob *pBlob){ blob_append(pBlob, sqlite3_column_blob(pStmt->pStmt, N), sqlite3_column_bytes(pStmt->pStmt, N)); } Blob db_column_text_as_blob(Stmt *pStmt, int N){ Blob x; blob_init(&x, sqlite3_column_text(pStmt->pStmt,N), sqlite3_column_bytes(pStmt->pStmt,N)); return x; } /* ** Initialize a blob to an ephemeral copy of the content of a ** column in the current row. The data in the blob will become ** invalid when the statement is stepped or reset. */ |
︙ | ︙ |
Changes to src/smtp.c.
︙ | ︙ | |||
650 651 652 653 654 655 656 | @ CREATE TABLE IF NOT EXISTS repository.emailbox( @ euser TEXT, -- User who received this email @ edate INT, -- Date received. Seconds since 1970 @ efrom TEXT, -- Who is the email from @ emsgid INT, -- Raw email text @ ets INT, -- Transcript of the receiving SMTP session @ estate INT, -- Unread, read, starred, etc. | | > | 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | @ CREATE TABLE IF NOT EXISTS repository.emailbox( @ euser TEXT, -- User who received this email @ edate INT, -- Date received. Seconds since 1970 @ efrom TEXT, -- Who is the email from @ emsgid INT, -- Raw email text @ ets INT, -- Transcript of the receiving SMTP session @ estate INT, -- Unread, read, starred, etc. @ esubject TEXT, -- Subject line for display @ etags TEXT -- zero or more tags @ ); @ @ -- Information on how to deliver incoming email. @ CREATE TABLE IF NOT EXISTS repository.emailroute( @ eaddr TEXT PRIMARY KEY, -- Email address @ epolicy TEXT -- How to handle email sent to this address @ ) WITHOUT ROWID; |
︙ | ︙ | |||
681 682 683 684 685 686 687 688 689 690 691 692 693 694 | */ static const char zEmailDrop[] = @ DROP TABLE IF EXISTS emailblob; @ DROP TABLE IF EXISTS emailbox; @ DROP TABLE IF EXISTS emailroute; @ DROP TABLE IF EXISTS emailqueue; ; /* ** Populate the schema of a database. ** ** eForce==0 Fast ** eForce==1 Run CREATE TABLE statements every time ** eForce==2 DROP then rerun CREATE TABLE | > > > > > > > > > > | 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 | */ static const char zEmailDrop[] = @ DROP TABLE IF EXISTS emailblob; @ DROP TABLE IF EXISTS emailbox; @ DROP TABLE IF EXISTS emailroute; @ DROP TABLE IF EXISTS emailqueue; ; #if INTERFACE /* ** Mailbox message states */ #define MSG_UNREAD 0 #define MSG_READ 1 #define MSG_TRASH 2 #endif /* INTERFACE */ /* ** Populate the schema of a database. ** ** eForce==0 Fast ** eForce==1 Run CREATE TABLE statements every time ** eForce==2 DROP then rerun CREATE TABLE |
︙ | ︙ |
Changes to src/webmail.c.
︙ | ︙ | |||
115 116 117 118 119 120 121 122 123 124 125 126 127 128 | */ static int email_line_length(const char *z){ int i; for(i=0; z[i] && (z[i]!='\n' || z[i+1]==' ' || z[i+1]=='\t'); i++){} if( z[i]=='\n' ) i++; return i; } /* ** Return a pointer to the first non-whitespace character in z */ static const char *firstToken(const char *z){ while( fossil_isspace(*z) ){ z++; | > > > > > > > > > > > > > > > > > > > > > > > | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | */ static int email_line_length(const char *z){ int i; for(i=0; z[i] && (z[i]!='\n' || z[i+1]==' ' || z[i+1]=='\t'); i++){} if( z[i]=='\n' ) i++; return i; } /* ** Look for a parameter of the form NAME=VALUE in the given email ** header line. Return a copy of VALUE in space obtained from ** fossil_malloc(). Or return NULL if there is no such parameter. */ static char *email_hdr_value(const char *z, const char *zName){ int nName = (int)strlen(zName); int i; const char *z2 = strstr(z, zName); if( z2==0 ) return 0; z2 += nName; if( z2[0]!='=' ) return 0; z2++; if( z2[0]=='"' ){ z2++; for(i=0; z2[i] && z2[i]!='"'; i++){} if( z2[i]!='"' ) return 0; }else{ for(i=0; z2[i] && !fossil_isspace(z2[i]); i++){} } return mprintf("%.*s", i, z2); } /* ** Return a pointer to the first non-whitespace character in z */ static const char *firstToken(const char *z){ while( fossil_isspace(*z) ){ z++; |
︙ | ︙ | |||
176 177 178 179 180 181 182 | /* 123456789 123456 */ }else if( sqlite3_strnicmp(z2, "quoted-printable", 16)==0 ){ pBody->encoding = EMAILENC_QUOTED; }else{ pBody->encoding = EMAILENC_NONE; } } | > | > > > > > | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | /* 123456789 123456 */ }else if( sqlite3_strnicmp(z2, "quoted-printable", 16)==0 ){ pBody->encoding = EMAILENC_QUOTED; }else{ pBody->encoding = EMAILENC_NONE; } } if( bAddHeader ){ emailtoc_new_header_line(p, z+i); }else if( sqlite3_strnicmp(z+i, "Content-Disposition:", 20)==0 ){ /* 123456789 123456789 */ fossil_free(pBody->zFilename); pBody->zFilename = email_hdr_value(z+i, "filename"); } i += n; } if( multipartBody ){ p->nBody--; emailtoc_add_multipart(p, z+i); }else{ pBody->zContent = z+i; |
︙ | ︙ | |||
202 203 204 205 206 207 208 209 210 | EmailToc *p, /* Append the segments here */ char *z /* The body component. zero-terminated */ ){ int nB; /* Size of the boundary string */ int iStart; /* Start of the coding region past boundary mark */ int i; /* Loop index */ char *zBoundary = 0; /* Boundary marker */ /* Find the length of the boundary mark. */ | > > > > > > > > < > < > > > > > > > > > > > > > > > > > > > > | > > > > > | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | EmailToc *p, /* Append the segments here */ char *z /* The body component. zero-terminated */ ){ int nB; /* Size of the boundary string */ int iStart; /* Start of the coding region past boundary mark */ int i; /* Loop index */ char *zBoundary = 0; /* Boundary marker */ /* Skip forward to the beginning of the boundary mark. The boundary ** mark always begins with "--" */ while( z[0]!='-' || z[1]!='-' ){ while( z[0] && z[0]!='\n' ) z++; if( z[0]==0 ) return; z++; } /* Find the length of the boundary mark. */ zBoundary = z; for(nB=0; z[nB] && !fossil_isspace(z[nB]); nB++){} if( nB==0 ) return; z += nB; while( fossil_isspace(z[0]) ) z++; zBoundary[nB] = 0; for(i=iStart=0; z[i]; i++){ if( z[i]=='\n' && strncmp(z+i+1, zBoundary, nB)==0 ){ z[i+1] = 0; emailtoc_add_multipart_segment(p, z+iStart, 0); iStart = i+nB; if( z[iStart]=='-' && z[iStart+1]=='-' ) return; while( fossil_isspace(z[iStart]) ) iStart++; i = iStart; } } } /* ** Compute a table-of-contents (EmailToc) for the email message ** provided on the input. ** ** This routine will cause pEmail to become zero-terminated if it is ** not already. It will also insert zero characters into parts of ** the message, to delimit the various components. */ EmailToc *emailtoc_from_email(Blob *pEmail){ char *z; EmailToc *p = emailtoc_alloc(); blob_terminate(pEmail); z = blob_buffer(pEmail); emailtoc_add_multipart_segment(p, z, 1); return p; } /* ** Inplace-unfolding of an email header line. ** ** Actually - this routine works by converting all contiguous sequences ** of whitespace into a single space character. */ static void email_hdr_unfold(char *z){ int i, j; char c; for(i=j=0; (c = z[i])!=0; i++){ if( fossil_isspace(c) ){ c = ' '; if( j && z[j-1]==' ' ) continue; } z[j++] = c; } z[j] = 0; } /* ** COMMAND: test-decode-email ** ** Usage: %fossil test-decode-email FILE ** ** Read an rfc-2822 formatted email out of FILE, then write a decoding ** to stdout. Use for testing and validating the email decoder. */ void test_email_decode_cmd(void){ Blob email; EmailToc *p; int i; verify_all_options(); if( g.argc!=3 ) usage("FILE"); blob_read_from_file(&email, g.argv[2], ExtFILE); p = emailtoc_from_email(&email); fossil_print("%d header line and %d content segments\n", p->nHdr, p->nBody); for(i=0; i<p->nHdr; i++){ email_hdr_unfold(p->azHdr[i]); fossil_print("%3d: %s\n", i, p->azHdr[i]); } for(i=0; i<p->nBody; i++){ fossil_print("\nBODY %d mime \"%s\" encoding %d", i, p->aBody[i].zMimetype, p->aBody[i].encoding); if( p->aBody[i].zFilename ){ fossil_print(" filename \"%s\"", p->aBody[i].zFilename); } fossil_print("\n"); if( strncmp(p->aBody[i].zMimetype,"text/",5)!=0 ) continue; switch( p->aBody[i].encoding ){ case EMAILENC_B64: { int n = 0; decodeBase64(p->aBody[i].zContent, &n, p->aBody[i].zContent); fossil_print("%s", p->aBody[i].zContent); if( n && p->aBody[i].zContent[n-1]!='\n' ) fossil_print("\n"); break; |
︙ | ︙ | |||
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | ** that contains email received by the "fossil smtpd" command. */ void webmail_page(void){ int emailid; Stmt q; Blob sql; int showAll = 0; login_check_credentials(); if( g.zLogin==0 ){ login_needed(0); return; } if( !db_table_exists("repository","emailbox") ){ style_header("Webmail Not Available"); @ <p>This repository is not configured to provide webmail</p> style_footer(); return; } add_content_sql_commands(g.db); emailid = atoi(PD("id","0")); if( emailid>0 ){ blob_init(&sql, 0, 0); blob_append_sql(&sql, "SELECT decompress(etxt)" " FROM emailblob WHERE emailid=%d", emailid); if( !g.perm.Admin ){ blob_append_sql(&sql, " AND EXISTS(SELECT 1 FROM emailbox WHERE" " euser=%Q AND emsgid=emailid)", g.zLogin); } db_prepare_blob(&q, &sql); blob_reset(&sql); if( db_step(&q)==SQLITE_ROW ){ style_header("Message %d",emailid); | > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < < | > | | > > > | | | | | < > > > | | > | | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | ** that contains email received by the "fossil smtpd" command. */ void webmail_page(void){ int emailid; Stmt q; Blob sql; int showAll = 0; const char *zUser = 0; HQuery url; login_check_credentials(); if( g.zLogin==0 ){ login_needed(0); return; } if( !db_table_exists("repository","emailbox") ){ style_header("Webmail Not Available"); @ <p>This repository is not configured to provide webmail</p> style_footer(); return; } add_content_sql_commands(g.db); emailid = atoi(PD("id","0")); url_initialize(&url, "webmail"); if( g.perm.Admin ){ zUser = P("user"); if( zUser ){ url_add_parameter(&url, "user", zUser); if( fossil_strcmp(zUser,"*")==0 ){ showAll = 1; zUser = 0; } } } if( emailid>0 ){ style_submenu_element("Index", "%s", url_render(&url,"id",0,0,0)); blob_init(&sql, 0, 0); blob_append_sql(&sql, "SELECT decompress(etxt)" " FROM emailblob WHERE emailid=%d", emailid); if( !g.perm.Admin ){ blob_append_sql(&sql, " AND EXISTS(SELECT 1 FROM emailbox WHERE" " euser=%Q AND emsgid=emailid)", g.zLogin); } db_prepare_blob(&q, &sql); blob_reset(&sql); if( db_step(&q)==SQLITE_ROW ){ Blob msg = db_column_text_as_blob(&q, 0); url_add_parameter(&url, "id", P("id")); style_header("Message %d",emailid); if( PB("raw") ){ @ <pre>%h(db_column_text(&q, 0))</pre> style_submenu_element("Decoded", "%s", url_render(&url,"raw",0,0,0)); }else{ EmailToc *p = emailtoc_from_email(&msg); int i, j; style_submenu_element("Raw", "%s", url_render(&url,"raw","1",0,0)); @ <p> for(i=0; i<p->nHdr; i++){ char *z = p->azHdr[i]; email_hdr_unfold(z); for(j=0; z[j] && z[j]!=':'; j++){} if( z[j]!=':' ){ @ %h(z)<br> }else{ z[j] = 0; @ <b>%h(z):</b> %h(z+j+1)<br> } } for(i=0; i<p->nBody; i++){ @ <hr><b>Messsage Body #%d(i): %h(p->aBody[i].zMimetype) \ if( p->aBody[i].zFilename ){ @ "%h(p->aBody[i].zFilename)" } @ </b> if( strncmp(p->aBody[i].zMimetype, "text/", 5)!=0 ) continue; switch( p->aBody[i].encoding ){ case EMAILENC_B64: { int n = 0; decodeBase64(p->aBody[i].zContent, &n, p->aBody[i].zContent); break; } case EMAILENC_QUOTED: { int n = 0; decodeQuotedPrintable(p->aBody[i].zContent, &n); break; } } @ <pre>%h(p->aBody[i].zContent)</pre> } } style_footer(); db_finalize(&q); return; } db_finalize(&q); } style_header("Webmail"); blob_init(&sql, 0, 0); blob_append_sql(&sql, /* 0 1 2 3 4 5 */ "SELECT efrom, datetime(edate,'unixepoch'), estate, esubject, emsgid, euser" " FROM emailbox" ); if( showAll ){ style_submenu_element("My Emails", "%s", url_render(&url,"user",0,0,0)); }else if( zUser!=0 ){ style_submenu_element("All Users", "%s", url_render(&url,"user","*",0,0)); if( fossil_strcmp(zUser, g.zLogin)!=0 ){ style_submenu_element("My Emails", "%s", url_render(&url,"user",0,0,0)); } if( zUser ){ blob_append_sql(&sql, " WHERE euser=%Q", zUser); }else{ blob_append_sql(&sql, " WHERE euser=%Q", g.zLogin); } }else{ if( g.perm.Admin ){ style_submenu_element("All Users", "%s", url_render(&url,"user","*",0,0)); } blob_append_sql(&sql, " WHERE euser=%Q", g.zLogin); } blob_append_sql(&sql, " ORDER BY edate DESC limit 50"); db_prepare_blob(&q, &sql); blob_reset(&sql); @ <ol> while( db_step(&q)==SQLITE_ROW ){ char *zId = db_column_text(&q,4); const char *zFrom = db_column_text(&q, 0); const char *zDate = db_column_text(&q, 1); const char *zSubject = db_column_text(&q, 3); @ <li> if( showAll ){ const char *zTo = db_column_text(&q,5); @ <a href="%s(url_render(&url,"user",zTo,0,0))">%h(zTo)</a>: } @ <a href="%s(url_render(&url,"id",zId,0,0))">\ @ %h(zFrom) → %h(zSubject)</a> @ %h(zDate) } db_finalize(&q); @ </ol> style_footer(); } |