static void test_canonicalise(void) { char *addr; addr = address_canonicalise("Fred Bloggs <*****@*****.**>"); CU_ASSERT_STRING_EQUAL(addr, "*****@*****.**"); free(addr); }
/* look for myaddr and myaddrs in the body of a header - return the match */ static char* look_for_me(char *myaddr, int numaddresses, bytecode_input_t *bc, int i, const char **body) { char *found = NULL; int l; int curra,x ; /* loop through each TO header */ for (l = 0; body[l] != NULL && !found; l++) { struct address_itr ai; const struct address *a; address_itr_init(&ai, body[l]); /* loop through each address in the header */ while (!found && (a = address_itr_next(&ai)) != NULL) { char *addr = address_get_all(a, 0); if (!addr) addr = xstrdup(""); if (!strcasecmp(addr, myaddr)) { free(addr); found = xstrdup(myaddr); break; } curra=i; for(x=0; x<numaddresses; x++) { char *altaddr; const char *str; curra = unwrap_string(bc, curra, &str, NULL); /* is this address one of my addresses? */ altaddr = address_canonicalise(str); if (!strcasecmp(addr,altaddr)) { free(altaddr); found=xstrdup(str); break; } free(altaddr); } free(addr); } address_itr_fini(&ai); } return found; }
/* Determine if we should respond to a vacation message */ static int shouldRespond(void * m, sieve_interp_t *interp, int numaddresses, bytecode_input_t* bc, int i, char **from, char **to) { const char **body; char buf[128]; char *myaddr = NULL; int l = SIEVE_OK, j; int curra, x; char *found = NULL; char *reply_to = NULL; /* Implementations SHOULD NOT respond to any message that contains a "List-Id" [RFC2919], "List-Help", "List-Subscribe", "List- Unsubscribe", "List-Post", "List-Owner" or "List-Archive" [RFC2369] header field. */ for (j = 0; list_fields[j]; j++) { strcpy(buf, list_fields[j]); if (interp->getheader(m, buf, &body) == SIEVE_OK) { l = SIEVE_DONE; break; } } /* Implementations SHOULD NOT respond to any message that has an "Auto-submitted" header field with a value other than "no". This header field is described in [RFC3834]. */ strcpy(buf, "auto-submitted"); if (interp->getheader(m, buf, &body) == SIEVE_OK) { /* we don't deal with comments, etc. here */ /* skip leading white-space */ while (*body[0] && Uisspace(*body[0])) body[0]++; if (strcasecmp(body[0], "no")) l = SIEVE_DONE; } /* is there a Precedence keyword of "junk | bulk | list"? */ /* XXX non-standard header, but worth checking */ strcpy(buf, "precedence"); if (interp->getheader(m, buf, &body) == SIEVE_OK) { /* we don't deal with comments, etc. here */ /* skip leading white-space */ while (*body[0] && Uisspace(*body[0])) body[0]++; if (!strcasecmp(body[0], "junk") || !strcasecmp(body[0], "bulk") || !strcasecmp(body[0], "list")) l = SIEVE_DONE; } /* Note: the domain-part of all addresses are canonicalized */ /* grab my address from the envelope */ if (l == SIEVE_OK) { strcpy(buf, "to"); l = interp->getenvelope(m, buf, &body); if (body[0]) myaddr = address_canonicalise(body[0]); } if (l == SIEVE_OK) { strcpy(buf, "from"); l = interp->getenvelope(m, buf, &body); } if (l == SIEVE_OK && body[0]) { /* we have to parse this address & decide whether we want to respond to it */ reply_to = address_canonicalise(body[0]); /* first, is there a reply-to address? */ if (reply_to == NULL) { l = SIEVE_DONE; } /* first, is it from me? */ if (l == SIEVE_OK && myaddr && !strcmp(myaddr, reply_to)) { l = SIEVE_DONE; } /* ok, is it any of the other addresses i've specified? */ if (l == SIEVE_OK) { curra=i; for(x=0; x<numaddresses; x++) { const char *address; curra = unwrap_string(bc, curra, &address, NULL); if (!strcmp(address, reply_to)) l = SIEVE_DONE; } } /* ok, is it a system address? */ if (l == SIEVE_OK && sysaddr(reply_to)) { l = SIEVE_DONE; } } if (l == SIEVE_OK) { /* ok, we're willing to respond to the sender. but is this message to me? that is, is my address in the [Resent]-To, [Resent]-Cc or [Resent]-Bcc fields? */ if (strcpy(buf, "to"), interp->getheader(m, buf, &body) == SIEVE_OK) found = look_for_me(myaddr, numaddresses ,bc, i, body); if (!found && (strcpy(buf, "cc"), (interp->getheader(m, buf, &body) == SIEVE_OK))) found = look_for_me(myaddr, numaddresses, bc, i, body); if (!found && (strcpy(buf, "bcc"), (interp->getheader(m, buf, &body) == SIEVE_OK))) found = look_for_me(myaddr, numaddresses, bc, i, body); if (!found && (strcpy(buf, "resent-to"), (interp->getheader(m, buf, &body) == SIEVE_OK))) found = look_for_me(myaddr, numaddresses ,bc, i, body); if (!found && (strcpy(buf, "resent-cc"), (interp->getheader(m, buf, &body) == SIEVE_OK))) found = look_for_me(myaddr, numaddresses, bc, i, body); if (!found && (strcpy(buf, "resent-bcc"), (interp->getheader(m, buf, &body) == SIEVE_OK))) found = look_for_me(myaddr, numaddresses, bc, i, body); if (!found) l = SIEVE_DONE; } /* ok, ok, if we got here maybe we should reply */ if (myaddr) free(myaddr); *from = found; *to = reply_to; return l; }