diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-11-27 21:47:16 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2008-11-27 21:47:16 +0000 |
commit | cda341cfb2d39b03c40af4153a7f27fa3827bf0b (patch) | |
tree | 6041225c6d57112d291396fb373906c9ea2764a0 /mfd | |
parent | f3373b03784ab08ab74a1bac5c18440fbc9a815f (diff) | |
download | mailfromd-cda341cfb2d39b03c40af4153a7f27fa3827bf0b.tar.gz mailfromd-cda341cfb2d39b03c40af4153a7f27fa3827bf0b.tar.bz2 |
Minor changes.
* pmult/pmult.c: Remove obsolete comment.
* mfd/engine.c (run_msgmod): Ensure the message for gacopyz_replace_body
has \r\n endings.
git-svn-id: file:///svnroot/mailfromd/trunk@1762 7a8a7f39-df28-0410-adc6-e0d955640f24
Diffstat (limited to 'mfd')
-rw-r--r-- | mfd/engine.c | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/mfd/engine.c b/mfd/engine.c index 741c74d1..d92f6163 100644 --- a/mfd/engine.c +++ b/mfd/engine.c @@ -1135,6 +1135,83 @@ mlfi_body(SMFICTX *ctx, unsigned char *bodyp, size_t len) return status; } +size_t +mem_search(const char *str, int c, size_t size) +{ + const char *p; + + if (size == 0) + return 0; + p = memchr(str, c, size); + if (p) + return p - str; + return size; +} + +int +xlate_and_replace_body(SMFICTX *ctx, const char *value, size_t size) +{ + int rc; + mu_opool_t pool; + + if (mu_opool_create(&pool, 0)) { + mu_error(_("Cannot create opool: %s"), mu_strerror(rc)); + return 1; + } + + while (size) { + size_t n = mem_search(value, '\n', size); + size_t off; + + if (value[n] == '\n') { + off = n + 1; + if (n > 0 && value[n-1] == '\r') + n--; + } else + off = n; + + if ((rc = mu_opool_append(pool, value, n)) != 0 + || (rc = mu_opool_append(pool, "\r\n", 2)) != 0) { + mu_error(_("Failed to append to opool: %s"), + mu_strerror(rc)); + break; + } + + value += off; + size -= off; + } + + if (rc == 0) { + mu_iterator_t itr; + rc = mu_opool_get_iterator(pool, &itr); + if (rc) { + mu_error(_("%s failed: %s"), + "mu_opool_iterator_create", + mu_strerror(rc)); + } else { + for (mu_iterator_first (itr); + !mu_iterator_is_done (itr); + mu_iterator_next (itr)) { + const char *ptr; + size_t len; + mu_iterator_current_kv (itr, + (void**)&len, + (const void **)&ptr); + rc = gacopyz_replace_body(ctx, ptr, len); + if (rc) { + mu_error(_("%s failed: %s"), + "gacopyz_replace_body", + mu_strerror(errno)); + break; + } + } + mu_iterator_destroy (&itr); + } + } + mu_opool_destroy (&pool); + return rc; +} + static int run_msgmod(void *item, void *data) { @@ -1175,7 +1252,7 @@ run_msgmod(void *item, void *data) break; case body_repl: - gacopyz_replace_body(ctx, hdr->value, strlen(hdr->value)); + xlate_and_replace_body(ctx, hdr->value, strlen(hdr->value)); } return 0; } |