Fossil Forum

how to have the email value for a new ticket filled automatically
Login

how to have the email value for a new ticket filled automatically

how to have the email value for a new ticket filled automatically

(1) By jose i cabrera (jicman) on 2023-01-20 21:23:49 [source]

Hi. When creating a new ticket, the email textbox is empty. Is there a way to have it filled automatically? Like the user email, etc.? Thanks.

(2) By Stephan Beal (stephan) on 2023-01-20 23:10:30 in reply to 1 [link] [source]

When creating a new ticket, the email textbox is empty. Is there a way to have it filled automatically? Like the user email, etc.?

Interestingly, fossil doesn't actually have a field for user email addresses - those are only stored for subscribers, a separate type of user account which was added to support the forum. Since the ticket template is th1, it can be pre-filled with almost anything by editing the template, but it does not have access to a user's email address.

(3) By Warren Young (wyoung) on 2023-01-21 04:30:50 in reply to 2 [link] [source]

fossil doesn't actually have a field for user email addresses

Specifically, literally an “email” field? No, but

That in turn is queried here.

Interestingly, it isn't queried when building the initial /subscribe page. You're made to put it in manually, and then it's carried through the initial POST into the rest of the alert sign-up process.

(4) By jose i cabrera (jicman) on 2023-01-23 00:30:13 in reply to 3 [link] [source]

Thanks for this I tried:

19:04:53.70>fossil user contact jcabrera jose@jic.com
jose@jic.com

But when I run the 'fossil server', and try to create a new ticket, the email address is still empty. Thoughts?

(5) By jose i cabrera (jicman) on 2023-01-23 00:43:01 in reply to 4 [link] [source]

19:30:25.30>fossil user list
anonymous    Anon
developer    Dev
jcabrera     jose@jic.com
nobody       Nobody
reader       Reader

The user list does show the change, but the automatic filling does not take place.

(6) By mark on 2023-01-23 06:54:01 in reply to 1 [link] [source]

Please try the below diff. It should only work for logged-in users with a well-formed email address set as their contact information (e.g., fossil user contact $user user@addr.net)

Index: src/tkt.c
=======================================================================
hash - 427f4dc408e01b69c5c47e0270f460cd1aab3d04d7277c1f1631401b23781a61
hash + 85842d3bfdbceaf7461a36d6c00898ffe50248a8f1316bd2d4a862b3a5b1c92a
--- src/tkt.c
+++ src/tkt.c
@@ -996,7 +996,8 @@ void tktnew_page(void){
 */
 void tktnew_page(void){
   const char *zScript;
-  char *zNewUuid = 0;
+  char *zEmail = 0, *zNewUuid = 0;
+  int uid;
 
   login_check_credentials();
   if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; }
@@ -1018,6 +1019,15 @@ void tktnew_page(void){
     @ <input type="hidden" name="date_override" value="%h(P("date_override"))">
   }
   zScript = ticket_newpage_code();
+  if( g.zLogin && g.zLogin[0] ){
+    uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin);
+    if( uid ){
+      zEmail = db_text(0, "SELECT info FROM user WHERE uid=%d", uid);
+      if( zEmail && email_address_is_valid(zEmail, 0) ){
+        Th_Store("private_contact", zEmail);
+      }
+    }
+  }
   Th_Store("login", login_name());
   Th_Store("date", db_text(0, "SELECT datetime('now')"));
   Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd,

(7) By jose i cabrera (jicman) on 2023-01-23 15:37:09 in reply to 6 [link] [source]

Please try the below diff...

Thanks. I will try this, but, I prefer not to make changes to the code. I would rather see if the fossil developers can incorporate it in the original source.

(9) By Daniel Dumitriu (danield) on 2023-01-23 16:06:29 in reply to 7 [link] [source]

We need at least some feedback that some change works as expected/wanted, especially from the first (only?) person that asked for it - and that before putting it on trunk. In fact, that is only the first precondition.

Compiling Fossil is really easy on Unix descendants.

(10) By mark on 2023-01-23 16:10:35 in reply to 7 [link] [source]

Thanks. I will try this, but, I prefer not to make changes to the code. I would rather see if the fossil developers can incorporate it in the original source.

That was the point of the diff: if you could please test it and let me know if it works, I can polish the diff and commit it :)

But we need to confirm it satisfies requirements and works first.

(11.1) By mark on 2023-01-23 16:12:43 edited from 11.0 in reply to 7 [link] [source]

Deleted

(8) By Warren Young (wyoung) on 2023-01-23 16:01:54 in reply to 6 [link] [source]

The user.info field doesn't have to contain an email address and nothing else. It is often an RFC 822 recipient string like:

    Warren Young <me@example.com>

Thus the custom find_emailaddr() SQL function registered within Fossil for this purpose, exemplified in my link above, which looks for the angle brackets and extracts what is in between.

(12) By mark on 2023-01-23 16:14:44 in reply to 8 [link] [source]

I missed your post, and wasn't aware we had that SQL function--thanks!

If jose confirms the diff works for the simple case, I'll update the diff.

(13.1) By jose i cabrera (jicman) on 2023-01-23 19:21:40 edited from 13.0 in reply to 8 [link] [source]

14:14:53.78>fossil user list
anonymous    Anon
developer    Dev
jcabrera     Jose Cabrera <jose@jic.com>
nobody       Nobody
reader       Reader

This is the user list, but, it still does not fill the email address for new tickets. This one is also adding quoted:

14:20:45.42>fossil user list
anonymous    Anon
developer    Dev
jcabrera     "Jose <jose@jic.com>"
nobody       Nobody
reader       Reader

(14.1) By jose i cabrera (jicman) on 2023-01-23 19:55:26 edited from 14.0 in reply to 6 [link] [source]

Please try the below diff...

I have downloaded the latest version and added the changes prescribed above. The problem is that I am cross-compiling for Windows 10 x64. This is the command that I use to create a Windows x64 sqlite3.exe tool:

./configure --host=x86_64-w64-mingw32
make
x86_64-w64-mingw32-gcc shell.c -o sqlite3.exe sqlite3.c

What is the command that I can run to create the fossil x64 for Windows?

(15) By jose i cabrera (jicman) on 2023-01-23 20:27:18 in reply to 14.1 [link] [source]

What is the command that I can run to create the fossil x64 for Windows?

I still need that command above to build a fossil.exe that I can place in a windows folder and use outside cygwin as I do with sqlite3.exe. However, I was able to compile it with just configure and make under cygwin, and this is what I found:

jose <jose@jic.com> does not work.
"jose <jose@jic.com>" does not work.
<jose@jic.com> does not work.
jose@jic.com works.

So, any of these above should work, and the email should be extracted and place in the email of the person entering the ticket automatically. Thanks for the help, guys.

(16) By mark on 2023-01-24 00:52:11 in reply to 15 [link] [source]

jose@jic.com works

Great! Thanks, for testing. I wasn't sure if I had set the correct Th1 var.


Thus the custom find_emailaddr() SQL function registered within Fossil for this purpose, exemplified in my link above, which looks for the angle brackets and extracts what is in between.

Thanks to wyoung@, as he explains in the quoted post, we have a SQL function that parses emails from RFC 822 formatted strings. However, it only returns a string if the info field contains a well-formed email in between "<...>"; that is, for a contact-info field of usr@addr.net, an empty string or NULL is returned^. As such, we need both queries to cover our bases.

Updated diff below should work for contact-info fields that contain a well-formed email address irrespective of whether it is enclosed between angle brackets; that is, any of the forms in your post:

Index: src/tkt.c
=======================================================================
hash - 427f4dc408e01b69c5c47e0270f460cd1aab3d04d7277c1f1631401b23781a61
hash + 1958448ee80935ba617292e3d4716db36c2bb18f1f3134fc8c47089f5fd6954c
--- src/tkt.c
+++ src/tkt.c
@@ -996,7 +996,8 @@ void tktnew_page(void){
 */
 void tktnew_page(void){
   const char *zScript;
-  char *zNewUuid = 0;
+  char *zEmail = 0, *zNewUuid = 0;
+  int uid;
 
   login_check_credentials();
   if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; }
@@ -1018,6 +1019,19 @@ void tktnew_page(void){
     @ <input type="hidden" name="date_override" value="%h(P("date_override"))">
   }
   zScript = ticket_newpage_code();
+  if( g.zLogin && g.zLogin[0] ){
+    uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin);
+    if( uid ){
+      zEmail = db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d",
+          uid);
+      if( zEmail==0 || *zEmail==0 ){
+        zEmail = db_text(0, "SELECT info FROM user WHERE uid=%d", uid);
+      }
+      if( zEmail ){
+        Th_Store("private_contact", zEmail);
+      }
+    }
+  }
   Th_Store("login", login_name());
   Th_Store("date", db_text(0, "SELECT datetime('now')"));
   Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd,

^: Interestingly, although the comments suggest NULL is returned, it appears an empty string is returned in testing.

(18.1) By mark on 2023-01-24 10:59:09 edited from 18.0 in reply to 16 [link] [source]

After discussing this in /chat, we decided it would be good to adapt the SQL find_emailaddr() routine to parse email addresses from strings that are not necessarily enclosed in angle brackets.

The below diff makes this improvement albeit with a minimal change. As such, we can drop the fallback query when prepopulating the email field, and parse addresses from less common, or even malformed RFC 822 formatted, contact-info strings--not just the more common well-formed RFC 822 and plain address case; for example:

fossil user contact bob "bob hacker: bob@hacks.net"
fossil user contact bob "bob hacker=bob@hacks.net"
fossil user contact bob "hacker, bob bob@hacks.net"
fossil user contact bob "bob@hacks.net, bob hacker"
fossil user contact bob "bob hacker, bob@hacks.net"
fossil user contact bob "bob hacker <bob@hacks.net"
fossil user contact bob "bob hacker bob@hacks.net>"
fossil user contact bob "<bob hacker> bob@hacks.net"
...

However, the logic hasn't been upgraded to parse any arbitrary string; for example, hacker;bob@hacks.net won't work (while `hacker; bob@hacks.net would). I'm not sure that accepting any arbitrary string is necessary or worth the code cost--I think the current logic and set of delimiters handle the most common cases--but if you disagree, we can make further changes.

Index: src/alerts.c
=======================================================================
hash - af90ba153fc74916ef71703154b371c5c8f91a74484c2f370726db5dc93823fe
hash + 6d3fc33fbefe46b46dbf41e89022f6d1ad2ed0070c993dafaed6629b228f94ab
--- src/alerts.c
+++ src/alerts.c
@@ -716,8 +716,8 @@ int email_address_is_valid(const char *z, char cTerm){
 ** Make a copy of the input string up to but not including the
 ** first cTerm character.
 **
-** Verify that the string really that is to be copied really is a
-** valid email address.  If it is not, then return NULL.
+** Verify that the string to be copied really is a valid
+** email address.  If it is not, then return NULL.
 **
 ** This routine is more restrictive than necessary.  It does not
 ** allow comments, IP address, quoted strings, or certain uncommon
@@ -730,7 +730,8 @@ char *email_copy_addr(const char *z, char cTerm ){
 }
 
 /*
-** Scan the input string for a valid email address enclosed in <...>
+** Scan the input string for a valid email address that may be
+** enclosed in <...>, or delimited by ',' or ':' or '=' or ' '.
 ** If the string contains one or more email addresses, extract the first
 ** one into memory obtained from mprintf() and return a pointer to it.
 ** If no valid email address can be found, return NULL.
@@ -737,13 +738,13 @@ char *alert_find_emailaddr(const char *zIn){
 */
 char *alert_find_emailaddr(const char *zIn){
   char *zOut = 0;
-  while( zIn!=0 ){
-     zIn = (const char*)strchr(zIn, '<');
-     if( zIn==0 ) break;
-     zIn++;
-     zOut = email_copy_addr(zIn, '>');
-     if( zOut!=0 ) break;
-  }
+  do{
+    zOut = email_copy_addr(zIn, zIn[strcspn(zIn, ">,:= ")]);
+    if( zOut!=0 ) break;
+    zIn = (const char *)strpbrk(zIn, "<,:= ");
+    if( zIn==0 ) break;
+    zIn++;
+  }while( zIn!=0 );
   return zOut;
 }
 

Index: src/tkt.c
=======================================================================
hash - 427f4dc408e01b69c5c47e0270f460cd1aab3d04d7277c1f1631401b23781a61
hash + 0b7fa6af67d53448ea1b2a4548453fdb908cbce4ceaf9826f30913438ac94903
--- src/tkt.c
+++ src/tkt.c
@@ -996,7 +996,8 @@ void tktnew_page(void){
 */
 void tktnew_page(void){
   const char *zScript;
-  char *zNewUuid = 0;
+  char *zEmail = 0, *zNewUuid = 0;
+  int uid;
 
   login_check_credentials();
   if( !g.perm.NewTkt ){ login_needed(g.anon.NewTkt); return; }
@@ -1018,6 +1019,16 @@ void tktnew_page(void){
     @ <input type="hidden" name="date_override" value="%h(P("date_override"))">
   }
   zScript = ticket_newpage_code();
+  if( g.zLogin && g.zLogin[0] ){
+    uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", g.zLogin);
+    if( uid ){
+      zEmail = db_text(0, "SELECT find_emailaddr(info) FROM user WHERE uid=%d",
+          uid);
+      if( zEmail ){
+        Th_Store("private_contact", zEmail);
+      }
+    }
+  }
   Th_Store("login", login_name());
   Th_Store("date", db_text(0, "SELECT datetime('now')"));
   Th_CreateCommand(g.interp, "submit_ticket", submitTicketCmd,

(20) By jose i cabrera (jicman) on 2023-01-25 13:56:50 in reply to 18.1 [link] [source]

Is there a way to enter this diffs automatically into the source files? Yes, you guessed it: newbie. :-)

(21) By Daniel Dumitriu (danield) on 2023-01-25 14:05:38 in reply to 20 [link] [source]

Go to your checkout root directory and say patch -p0 < PATCHFILE.

(22) By jose i cabrera (jicman) on 2023-01-25 14:22:20 in reply to 21 [link] [source]

Thanks.

(23) By jose i cabrera (jicman) on 2023-01-25 14:25:13 in reply to 18.1 [link] [source]

After discussing this in /chat, we decided it would be good to adapt the SQL find_emailaddr() …

This patch works as expected. At least with this entry,

jose cabrera <jose@jic.com>

the email is picked up and it's exactly what I need. I hope this patch gets into the next version.

(25) By jose i cabrera (jicman) on 2023-02-01 15:00:59 in reply to 18.1 [link] [source]

The below diff makes this improvement albeit with a minimal change. As such,...

This patch is working great. Is it going to be pushed to the fossil trunk? It would be nice, since I have to patch every time I build fossil. Thanks.

josé

(26) By mark on 2023-02-02 05:29:41 in reply to 25 [link] [source]

This patch is working great. Is it going to be pushed to the fossil trunk? It would be nice, since I have to patch every time I build fossil. Thanks.

Oh, yes, I forgot about this. If there are no objections or further related suggestions, I'll commit this tomorrow. Thanks for testing!

(27) By jose i cabrera (jicman) on 2023-02-02 18:21:02 in reply to 26 [link] [source]

If there are no objections or further related suggestions, I'll commit this tomorrow.

Thank you, sir.

Thanks for testing!

No, thank you for the patch. It's greatly appreciated.

(28) By mark on 2023-02-03 07:24:48 in reply to 27 [link] [source]

I thought it was a pretty good suggestion, so thanks again! This has landed on trunk

(29) By jose i cabrera (jicman) on 2023-02-03 13:19:06 in reply to 28 [link] [source]

Thanks. Just downloaded Fossil v2.21 [f974583f90] from trunk, built fossil, and it runs like a beautiful gazelle in the vast pastures of Africa.

(17) By Warren Young (wyoung) on 2023-01-24 01:13:24 in reply to 14.1 [link] [source]

It’s in §2.0, point 8, item c of the Fossil compilation doc, which is the first result for the search “compile mingw”.

(19) By jose i cabrera (jicman) on 2023-01-24 21:24:12 in reply to 17 [link] [source]

Thanks. Following your suggestion, I edited "win/Makefile.mingw", and made this change:

PREFIX = x86_64-w64-mingw32-

and then, ran this command,

$ make -f win/Makefile.mingw USE_WINDOWS=1 X64=1
make -C src/../compat/zlib PREFIX=x86_64-w64-mingw32- CC=x86_64-w64-mingw32-gcc  -f win32/Makefile.gcc libz.a
make[1]: Entering directory '/home/E608313/builds/fossil/Fossil-a80f2748/compat/zlib'
make[1]: 'libz.a' is up to date.
make[1]: Leaving directory '/home/E608313/builds/fossil/Fossil-a80f2748/compat/zlib'
wbld\translate.exe src/ajax.c >wbld/ajax_.c
/bin/sh: wbldtranslate.exe: command not found
make: *** [win/Makefile.mingw:1332: wbld/ajax_.c] Error 127

However, I can run:

./configure --host=x86_64-w64-mingw32 --with-openssl=none
make

and that builds fossil, but, I can not take it out of Cygwin. Any thoughts? Thanks.

(24) By jose i cabrera (jicman) on 2023-01-26 13:59:56 in reply to 14.1 [link] [source]

Just to leave the answer to this...

To build a x64 fossil.exe for Windows using Cygwin:
-- Edit the win/Makefile.mingw
-- Uncomment # PREFIX = x86_64-w64-mingw32-
-- Save win/Makefile.mingw
-- Run 'make -f win/Makefile.mingw'

And enjoy the beautiful iconized standalone Windows 10 fossil.exe tool.

Of course, make sure that you have added all the libraries needed to use x86_64-w64-mingw32-* tools.