9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Romano <unobe@cpan.org>
To: 9front@9front.org
Subject: [9front] [PATCH] upas: allow send to parse e-mail descriptions like marshal
Date: Wed, 08 May 2024 07:22:16 +0000	[thread overview]
Message-ID: <11AEA4EE6266EBCACF531DE32D2AA5B8@smtp.pobox.com> (raw)


	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);

             reply	other threads:[~2024-05-08  7:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08  7:22 Romano [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11AEA4EE6266EBCACF531DE32D2AA5B8@smtp.pobox.com \
    --to=unobe@cpan.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).