Fossil SCM
Add the find_emailaddr() SQL function.
Commit
8a20d41fce12bec5d275bf13f8158533eba96add3cdf3bb5b40e564417a3f871
Parent
2d732f4030e8501…
2 files changed
+2
+36
M
src/db.c
+2
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1000,10 +1000,12 @@ | ||
| 1000 | 1000 | db_hextoblob, 0, 0); |
| 1001 | 1001 | sqlite3_create_function(db, "capunion", 1, SQLITE_UTF8, 0, |
| 1002 | 1002 | 0, capability_union_step, capability_union_finalize); |
| 1003 | 1003 | sqlite3_create_function(db, "fullcap", 1, SQLITE_UTF8, 0, |
| 1004 | 1004 | capability_fullcap, 0, 0); |
| 1005 | + sqlite3_create_function(db, "find_emailaddr", 1, SQLITE_UTF8, 0, | |
| 1006 | + email_find_emailaddr_func, 0, 0); | |
| 1005 | 1007 | } |
| 1006 | 1008 | |
| 1007 | 1009 | #if USE_SEE |
| 1008 | 1010 | /* |
| 1009 | 1011 | ** This is a pointer to the saved database encryption key string. |
| 1010 | 1012 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1000,10 +1000,12 @@ | |
| 1000 | db_hextoblob, 0, 0); |
| 1001 | sqlite3_create_function(db, "capunion", 1, SQLITE_UTF8, 0, |
| 1002 | 0, capability_union_step, capability_union_finalize); |
| 1003 | sqlite3_create_function(db, "fullcap", 1, SQLITE_UTF8, 0, |
| 1004 | capability_fullcap, 0, 0); |
| 1005 | } |
| 1006 | |
| 1007 | #if USE_SEE |
| 1008 | /* |
| 1009 | ** This is a pointer to the saved database encryption key string. |
| 1010 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1000,10 +1000,12 @@ | |
| 1000 | db_hextoblob, 0, 0); |
| 1001 | sqlite3_create_function(db, "capunion", 1, SQLITE_UTF8, 0, |
| 1002 | 0, capability_union_step, capability_union_finalize); |
| 1003 | sqlite3_create_function(db, "fullcap", 1, SQLITE_UTF8, 0, |
| 1004 | capability_fullcap, 0, 0); |
| 1005 | sqlite3_create_function(db, "find_emailaddr", 1, SQLITE_UTF8, 0, |
| 1006 | email_find_emailaddr_func, 0, 0); |
| 1007 | } |
| 1008 | |
| 1009 | #if USE_SEE |
| 1010 | /* |
| 1011 | ** This is a pointer to the saved database encryption key string. |
| 1012 |
+36
| --- src/email.c | ||
| +++ src/email.c | ||
| @@ -619,10 +619,46 @@ | ||
| 619 | 619 | if( nDot==0 ) return 0; /* No "." in the domain */ |
| 620 | 620 | |
| 621 | 621 | /* If we reach this point, the email address is valid */ |
| 622 | 622 | return mprintf("%.*s", i, z); |
| 623 | 623 | } |
| 624 | + | |
| 625 | +/* | |
| 626 | +** Scan the input string for a valid email address enclosed in <...> | |
| 627 | +** If the string contains one or more email addresses, extract the first | |
| 628 | +** one into memory obtained from mprintf() and return a pointer to it. | |
| 629 | +** If no valid email address can be found, return NULL. | |
| 630 | +*/ | |
| 631 | +char *email_find_emailaddr(const char *zIn){ | |
| 632 | + char *zOut = 0; | |
| 633 | + while( zIn!=0 ){ | |
| 634 | + zIn = (const char*)strchr(zIn, '<'); | |
| 635 | + if( zIn==0 ) break; | |
| 636 | + zIn++; | |
| 637 | + zOut = email_copy_addr(zIn, '>'); | |
| 638 | + if( zOut!=0 ) break; | |
| 639 | + } | |
| 640 | + return zOut; | |
| 641 | +} | |
| 642 | + | |
| 643 | +/* | |
| 644 | +** SQL function: find_emailaddr(X) | |
| 645 | +** | |
| 646 | +** Return the first valid email address of the form <...> in input string | |
| 647 | +** X. Or return NULL if not found. | |
| 648 | +*/ | |
| 649 | +void email_find_emailaddr_func( | |
| 650 | + sqlite3_context *context, | |
| 651 | + int argc, | |
| 652 | + sqlite3_value **argv | |
| 653 | +){ | |
| 654 | + const char *zIn = (const char*)sqlite3_value_text(argv[0]); | |
| 655 | + char *zOut = email_find_emailaddr(zIn); | |
| 656 | + if( zOut ){ | |
| 657 | + sqlite3_result_text(context, zOut, -1, fossil_free); | |
| 658 | + } | |
| 659 | +} | |
| 624 | 660 | |
| 625 | 661 | /* |
| 626 | 662 | ** Return the hostname portion of an email address - the part following |
| 627 | 663 | ** the @ |
| 628 | 664 | */ |
| 629 | 665 |
| --- src/email.c | |
| +++ src/email.c | |
| @@ -619,10 +619,46 @@ | |
| 619 | if( nDot==0 ) return 0; /* No "." in the domain */ |
| 620 | |
| 621 | /* If we reach this point, the email address is valid */ |
| 622 | return mprintf("%.*s", i, z); |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | ** Return the hostname portion of an email address - the part following |
| 627 | ** the @ |
| 628 | */ |
| 629 |
| --- src/email.c | |
| +++ src/email.c | |
| @@ -619,10 +619,46 @@ | |
| 619 | if( nDot==0 ) return 0; /* No "." in the domain */ |
| 620 | |
| 621 | /* If we reach this point, the email address is valid */ |
| 622 | return mprintf("%.*s", i, z); |
| 623 | } |
| 624 | |
| 625 | /* |
| 626 | ** Scan the input string for a valid email address enclosed in <...> |
| 627 | ** If the string contains one or more email addresses, extract the first |
| 628 | ** one into memory obtained from mprintf() and return a pointer to it. |
| 629 | ** If no valid email address can be found, return NULL. |
| 630 | */ |
| 631 | char *email_find_emailaddr(const char *zIn){ |
| 632 | char *zOut = 0; |
| 633 | while( zIn!=0 ){ |
| 634 | zIn = (const char*)strchr(zIn, '<'); |
| 635 | if( zIn==0 ) break; |
| 636 | zIn++; |
| 637 | zOut = email_copy_addr(zIn, '>'); |
| 638 | if( zOut!=0 ) break; |
| 639 | } |
| 640 | return zOut; |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | ** SQL function: find_emailaddr(X) |
| 645 | ** |
| 646 | ** Return the first valid email address of the form <...> in input string |
| 647 | ** X. Or return NULL if not found. |
| 648 | */ |
| 649 | void email_find_emailaddr_func( |
| 650 | sqlite3_context *context, |
| 651 | int argc, |
| 652 | sqlite3_value **argv |
| 653 | ){ |
| 654 | const char *zIn = (const char*)sqlite3_value_text(argv[0]); |
| 655 | char *zOut = email_find_emailaddr(zIn); |
| 656 | if( zOut ){ |
| 657 | sqlite3_result_text(context, zOut, -1, fossil_free); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | /* |
| 662 | ** Return the hostname portion of an email address - the part following |
| 663 | ** the @ |
| 664 | */ |
| 665 |