Fossil

Check-in [0af01758]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work on the webmail interface. Still very incomplete.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | webmail
Files: files | file ages | folders
SHA3-256:0af017583ec46feb7c60c7328511c2f9f27243cff63e357e0e4b705527f1f6d8
User & Date: drh 2018-07-14 16:34:15
Context
2018-07-14
16:35
Merge changes from trunk. check-in: c1f8668b user: drh tags: webmail
16:34
Work on the webmail interface. Still very incomplete. check-in: 0af01758 user: drh tags: webmail
14:58
Work toward revamping the webmail page. check-in: d68879f7 user: drh tags: webmail
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/webmail.c.

361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
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
...
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
505




506
507
508
509
510
511
512

513
514
515

516
517
** This page can be used to read content from the EMAILBOX table
** that contains email received by the "fossil smtpd" command.
**
** Query parameters:
**
**     id=N                 Show a single email entry emailbox.ebid==N
**     f=N                  Display format.  0: decoded 1: raw
**     u=USER               Show mailbox for USER (admin only).
**     u=*                  Show mailbox for all users (admin only).
**     d=N                  0: inbox+unread 1: unread-only 2: trash 3: all
**     eN                   Select email entry emailbox.ebid==N
**     trash                Move selected entries to trash (estate=2)
**     read                 Mark selected entries as read (estate=1)
**     unread               Mark selected entries as unread (estate=0)
**  
*/
................................................................................
        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>
................................................................................
      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) &rarr; %h(zSubject)</a>
    @ %h(zDate)

  }
  db_finalize(&q);
  @ </ol>

  style_footer(); 
}







|
|







 







>

|
>


|
<





>


<
>

|



|







 







|
>
|
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








|

|





|




>
|

|
|
|
|
|
>
>
>
>


|

<
<
<
>


|
>


361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
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
...
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539



540
541
542
543
544
545
546
** This page can be used to read content from the EMAILBOX table
** that contains email received by the "fossil smtpd" command.
**
** Query parameters:
**
**     id=N                 Show a single email entry emailbox.ebid==N
**     f=N                  Display format.  0: decoded 1: raw
**     user=USER            Show mailbox for USER (admin only).
**     user=*               Show mailbox for all users (admin only).
**     d=N                  0: inbox+unread 1: unread-only 2: trash 3: all
**     eN                   Select email entry emailbox.ebid==N
**     trash                Move selected entries to trash (estate=2)
**     read                 Mark selected entries as read (estate=1)
**     unread               Mark selected entries as unread (estate=0)
**  
*/
................................................................................
        zUser = 0;
      }
    }
  }
  if( emailid>0 ){
    style_submenu_element("Index", "%s", url_render(&url,"id",0,0,0));
    blob_init(&sql, 0, 0);
    db_begin_transaction();
    blob_append_sql(&sql, "SELECT decompress(etxt)"
                          " FROM emailblob, emailbox"
                          " WHERE emailid=emsgid AND ebid=%d",
                          emailid);
    if( !g.perm.Admin ){
      blob_append_sql(&sql, " AND euser=%Q", 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);
      int eFormat = atoi(PD("f","0"));
      url_add_parameter(&url, "id", P("id"));
      style_header("Message %d",emailid);

      if( eFormat==1 ){
        @ <pre>%h(db_column_text(&q, 0))</pre>
        style_submenu_element("Decoded", "%s", url_render(&url,"f",0,0,0));
      }else{      
        EmailToc *p = emailtoc_from_email(&msg);
        int i, j;
        style_submenu_element("Raw", "%s", url_render(&url,"f","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>
................................................................................
      return;
    }
    db_finalize(&q);
  }
  style_header("Webmail");
  blob_init(&sql, 0, 0);
  blob_append_sql(&sql,
    "SELECT ebid,"                   /* 0 */
    " efrom,"                        /* 1 */
    " datetime(edate,'unixepoch'),"  /* 2 */
    " estate,"                       /* 3 */
    " esubject,"                     /* 4 */
    " euser"                         /* 5 */
    " FROM emailbox"
  );
  switch( atoi(PD("d","0")) ){
    case 0: {   /* Show unread and read */
      blob_append_sql(&sql, " WHERE estate<=1");
      break;
    }
    case 1: {   /* Unread messages only */
      blob_append_sql(&sql, " WHERE estate=0");
      break;
    }
    case 2: {   /* Trashcan only */
      blob_append_sql(&sql, " WHERE estate=2");
      break;
    }
    case 3: {   /* Everything */
      blob_append_sql(&sql, " WHERE 1");
      break;
    }
  }

  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, " AND euser=%Q", zUser);
    }else{
      blob_append_sql(&sql, " AND 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, " AND euser=%Q", g.zLogin);
  }
  blob_append_sql(&sql, " ORDER BY edate DESC limit 50");
  db_prepare_blob(&q, &sql);
  blob_reset(&sql);
  @ <form action="%R/webmail" method="POST">
  @ <table>
  while( db_step(&q)==SQLITE_ROW ){
    const char *zId = db_column_text(&q,0);
    const char *zFrom = db_column_text(&q, 1);
    const char *zDate = db_column_text(&q, 2);
    const char *zSubject = db_column_text(&q, 4);
    @ <tr>
    @ <td><input type="checkbox" name="e%s(zId)"></td>
    @ <td>%h(zFrom)</td>
    @ <td><a href="%s(url_render(&url,"id",zId,0,0))">%h(zSubject)</a> \
    @ %s(zDate)</td>
    if( showAll ){
      const char *zTo = db_column_text(&q,5);
      @ <td><a href="%s(url_render(&url,"user",zTo,0,0))">%h(zTo)</a></td>
    }



    @ </tr>
  }
  db_finalize(&q);
  @ </table>
  @ </form>
  style_footer(); 
}