From: Pierre Habouzit Date: Sat, 7 Apr 2007 12:36:56 +0000 (+0200) Subject: properly rewrite body_to_data_object: we must _add_ CR's not remove them :P X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=7f591b58f859555c0eb573477f9ff179bfc46751;p=apps%2Fmadmutt.git properly rewrite body_to_data_object: we must _add_ CR's not remove them :P Signed-off-by: Pierre Habouzit --- diff --git a/crypt.c b/crypt.c index ba50f4a..7156006 100644 --- a/crypt.c +++ b/crypt.c @@ -259,10 +259,10 @@ static gpgme_data_t create_gpgme_data(void) static gpgme_data_t body_to_data_object(BODY *a, int convert) { gpgme_data_t data; + FILE *fptmp; int err = 0; - FILE *fptmp = tmpfile(); - if (!fptmp) { + if (!(fptmp = tmpfile())) { mutt_perror (_("Can't create temporary file")); return NULL; } @@ -277,15 +277,14 @@ static gpgme_data_t body_to_data_object(BODY *a, int convert) int spare = 0; data = create_gpgme_data(); + while (fgets(buf + spare, sizeof(buf) - 1, fptmp)) { int l = m_strlen(buf); spare = buf[l - 1] != '\n'; - if (!spare) { - if (l > 2 && buf[l - 2] == '\r') { - buf[l - 2] = '\n'; - l--; - } + if (!spare && (l <= 1 || buf[l - 2] != '\r')) { + buf[l - 1] = '\r'; + buf[l++] = '\n'; } gpgme_data_write(data, buf, l - spare); if (spare) @@ -294,15 +293,16 @@ static gpgme_data_t body_to_data_object(BODY *a, int convert) if (spare) gpgme_data_write(data, buf, 1); gpgme_data_seek(data, 0, SEEK_SET); - } else { - err = gpgme_data_new_from_stream(&data, fptmp); + m_fclose(&fptmp); + return data; } + + err = gpgme_data_new_from_stream(&data, fptmp); m_fclose(&fptmp); if (err) { mutt_error (_("error allocating data object: %s\n"), gpgme_strerror (err)); return NULL; } - return data; }