+\f/*
+** REMOTENAME -- return the name relative to the current mailer
+**
+** Parameters:
+** name -- the name to translate.
+** m -- the mailer that we want to do rewriting relative
+** to.
+** senderaddress -- if set, uses the sender rewriting rules
+** rather than the recipient rewriting rules.
+** canonical -- if set, strip out any comment information,
+** etc.
+**
+** Returns:
+** the text string representing this address relative to
+** the receiving mailer.
+**
+** Side Effects:
+** none.
+**
+** Warnings:
+** The text string returned is tucked away locally;
+** copy it if you intend to save it.
+*/
+
+char *
+remotename(name, m, senderaddress, canonical)
+ char *name;
+ struct mailer *m;
+ bool senderaddress;
+ bool canonical;
+{
+ register char **pvp;
+ char *fancy;
+ extern char *macvalue();
+ char *oldg = macvalue('g', CurEnv);
+ static char buf[MAXNAME];
+ char lbuf[MAXNAME];
+ char pvpbuf[PSBUFSIZE];
+ extern char **prescan();
+ extern char *crackaddr();
+
+ if (tTd(12, 1))
+ printf("remotename(%s)\n", name);
+
+ /* don't do anything if we are tagging it as special */
+ if ((senderaddress ? m->m_s_rwset : m->m_r_rwset) < 0)
+ return (name);
+
+ /*
+ ** Do a heuristic crack of this name to extract any comment info.
+ ** This will leave the name as a comment and a $g macro.
+ */
+
+ if (canonical)
+ fancy = "\001g";
+ else
+ fancy = crackaddr(name);
+
+ /*
+ ** Turn the name into canonical form.
+ ** Normally this will be RFC 822 style, i.e., "user@domain".
+ ** If this only resolves to "user", and the "C" flag is
+ ** specified in the sending mailer, then the sender's
+ ** domain will be appended.
+ */
+
+ pvp = prescan(name, '\0', pvpbuf);
+ if (pvp == NULL)
+ return (name);
+ rewrite(pvp, 3);
+ if (CurEnv->e_fromdomain != NULL)
+ {
+ /* append from domain to this address */
+ register char **pxp = pvp;
+
+ /* see if there is an "@domain" in the current name */
+ while (*pxp != NULL && strcmp(*pxp, "@") != 0)
+ pxp++;
+ if (*pxp == NULL)
+ {
+ /* no.... append the "@domain" from the sender */
+ register char **qxq = CurEnv->e_fromdomain;
+
+ while ((*pxp++ = *qxq++) != NULL)
+ continue;
+ rewrite(pvp, 3);
+ }
+ }
+
+ /*
+ ** Do more specific rewriting.
+ ** Rewrite using ruleset 1 or 2 depending on whether this is
+ ** a sender address or not.
+ ** Then run it through any receiving-mailer-specific rulesets.
+ */
+
+ if (senderaddress)
+ {
+ rewrite(pvp, 1);
+ if (m->m_s_rwset > 0)
+ rewrite(pvp, m->m_s_rwset);
+ }
+ else
+ {
+ rewrite(pvp, 2);
+ if (m->m_r_rwset > 0)
+ rewrite(pvp, m->m_r_rwset);
+ }
+
+ /*
+ ** Do any final sanitation the address may require.
+ ** This will normally be used to turn internal forms
+ ** (e.g., user@host.LOCAL) into external form. This
+ ** may be used as a default to the above rules.
+ */
+
+ rewrite(pvp, 4);
+
+ /*
+ ** Now restore the comment information we had at the beginning.
+ */
+
+ cataddr(pvp, lbuf, sizeof lbuf);
+ define('g', lbuf, CurEnv);
+ expand(fancy, buf, &buf[sizeof buf - 1], CurEnv);
+ define('g', oldg, CurEnv);
+
+ if (tTd(12, 1))
+ printf("remotename => `%s'\n", buf);
+ return (buf);
+}