9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] upas: allow send to parse e-mail descriptions like marshal
@ 2024-05-08  7:22 Romano
  2024-05-16 22:50 ` Romano
  0 siblings, 1 reply; 6+ messages in thread
From: Romano @ 2024-05-08  7:22 UTC (permalink / raw)
  To: 9front


	upas/marshal/marshal.c:/^printfrom parses an e-mail with a description
	(e.g., "A Name <a.name@example.com>") and sets the from to just the
	e-mail address portion. This does the same for upas/send so that
	upasname='A name <a.name@example.com>' can be used to both set the From:
	in marshal with a description and to match the correct from in send
	for sending via smtp.
---
diff a327175a3c01d18e3e4c061ce4579cc420ee3561 daebe6f5e2a6df18729e08319c0ab70aad8e1666
--- a/sys/src/cmd/upas/send/message.c
+++ b/sys/src/cmd/upas/send/message.c
@@ -1,6 +1,7 @@
 #include "common.h"
 #include "send.h"
 #include <regexp.h>
+#include <ctype.h>
 #include "../smtp/smtp.h"
 #include "../smtp/rfc822.tab.h"
 
@@ -18,6 +19,24 @@
 static String*	getstring(Node *p);
 static String*	getaddr(Node *p);
 
+char *
+userfrom(char *cp)
+{
+	char *s, *r;
+	int n;
+
+	if((n = strlen(cp)) > 4 && cp[n-1] == '>'){
+		if((s = strrchr(cp, '<')) != nil && s != cp && isspace(s[-1])) {
+			s++;
+			strncpy(r, s, n - sizeof s);
+			r[strlen(s)-1] = '\0';
+			return r;
+		}
+	}
+
+	return cp;
+}
+
 int
 default_from(message *mp)
 {
@@ -32,7 +51,7 @@
 		return -1;
 	}
 	if(cp && *cp)
-		s_append(mp->sender, cp);
+		s_append(mp->sender, userfrom(cp));
 	else
 		s_append(mp->sender, lp);
 	free(cp);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-20  5:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08  7:22 [9front] [PATCH] upas: allow send to parse e-mail descriptions like marshal Romano
2024-05-16 22:50 ` Romano
2024-05-17  8:23   ` Romano
2024-06-18 18:05   ` Romano
2024-06-19 22:53     ` Jacob Moody
2024-06-20  5:27       ` Romano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).