9front - general discussion about 9front
 help / color / mirror / Atom feed
From: Romano <me+unobe@fallglow.com>
To: 9front@9front.org
Subject: Re: [9front] [PATCH] upas: allow send to parse e-mail descriptions like marshal
Date: Fri, 17 May 2024 01:23:35 -0700	[thread overview]
Message-ID: <E0222A25BE1B3CA020000CBDF5B4C432@smtp.pobox.com> (raw)
In-Reply-To: <FF3A32AD5C1A06D210B478808E525CE0@smtp.pobox.com>

Crap, after taking some more time to test, I realized that both
patches were copying more than need be at times, and the second
patch actually truncated the address too much most of the time. I
RTFM for strncpy because I didn't get why the last patch I sent
was so faulty. I thought it might have been char-by-char copying
backwards or something in the implementation. Alas, no, it was
me not understanding what was happening with re: to the index
where I was setting the null byte.

This is the last patch I'll send re: this until I get some feedback
or until June. And my apologies for anyone who read the previous
iterations already.

From: Romano <me+git@fallglow.com>
Date: Fri, 17 May 2024 08:08:34 +0000
Subject: [PATCH] upas/send: parse e-mail descriptions like marshal


/sys/src/cmd/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 upas/send
for sending via smtp.
---
diff e51d4aa069548de51d0e88a6d621d278e9138cd0 863b4ae53732ddeaf96dc23b0e9924651f2b4090
--- 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,23 @@
 static String*	getstring(Node *p);
 static String*	getaddr(Node *p);
 
+char *
+userfrom(char *cp)
+{
+	char *s;
+	int n;
+
+	if((n = strlen(cp)) > 4 && cp[n-1] == '>'){
+		if((s = strrchr(cp, '<')) != nil && s != cp && isspace(s[-1])) {
+			s++;
+			cp[n-1] = '\0';
+			strcpy(cp, s);
+		}
+	}
+
+	return cp;
+}
+
 int
 default_from(message *mp)
 {
@@ -32,7 +50,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-17  8:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08  7:22 Romano
2024-05-16 22:50 ` Romano
2024-05-17  8:23   ` Romano [this message]
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=E0222A25BE1B3CA020000CBDF5B4C432@smtp.pobox.com \
    --to=me+unobe@fallglow.com \
    --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).