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;
}
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)
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;
}