Fossil SCM

Add the find_emailaddr() SQL function.

drh 2018-08-10 16:16 trunk
Commit 8a20d41fce12bec5d275bf13f8158533eba96add3cdf3bb5b40e564417a3f871
2 files changed +2 +36
+2
--- src/db.c
+++ src/db.c
@@ -1000,10 +1000,12 @@
10001000
db_hextoblob, 0, 0);
10011001
sqlite3_create_function(db, "capunion", 1, SQLITE_UTF8, 0,
10021002
0, capability_union_step, capability_union_finalize);
10031003
sqlite3_create_function(db, "fullcap", 1, SQLITE_UTF8, 0,
10041004
capability_fullcap, 0, 0);
1005
+ sqlite3_create_function(db, "find_emailaddr", 1, SQLITE_UTF8, 0,
1006
+ email_find_emailaddr_func, 0, 0);
10051007
}
10061008
10071009
#if USE_SEE
10081010
/*
10091011
** This is a pointer to the saved database encryption key string.
10101012
--- 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 @@
619619
if( nDot==0 ) return 0; /* No "." in the domain */
620620
621621
/* If we reach this point, the email address is valid */
622622
return mprintf("%.*s", i, z);
623623
}
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
+}
624660
625661
/*
626662
** Return the hostname portion of an email address - the part following
627663
** the @
628664
*/
629665
--- 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

Keyboard Shortcuts

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