- while (get_line() != EOF && *field && *field != '-') {
- if (strncasecmp(field, attach_hdr, length) != 0 ||
- field[length] != ':') {
- fprintf(composition_file, "%s\n", field);
+ for (compnum = 1, state = FLD2; state == FLD2 || state == BODY2;) {
+ switch (state = m_getfld2(state, &f, draft_file)) {
+ case LENERR2:
+ state = FLD2;
+ case FLD2:
+ compnum++;
+ if (strncasecmp(f.name, VRSN_FIELD, sizeof(VRSN_FIELD) - 1)==0) {
+ /*
+ ** The draft is already in MIME format, thus
+ ** back out and use the original draft file.
+ */
+ clean_up_temporary_files();
+ return DONE;
+ }
+ if (strncasecmp(f.name, attach_hdr, length) != 0 ||
+ f.namelen != length) {
+ fprintf(composition_file, "%s:%s", f.name, f.value);
+ }
+ break;
+ case BODY2:
+ if (!finished_header) {
+ fputs("--------\n", composition_file);
+ finished_header++;
+ }
+ fputs(f.value, body_file);
+ break;
+ case FILEEOF2:
+ break;
+ case FMTERR2:
+ adios(EX_DATAERR, NULL, "message format error in component #%d", compnum);
+ case IOERR2:
+ adios(EX_IOERR, NULL, "error reading draft file: %s", draft_file_name);
+ default:
+ adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);