bool TestExtMailparse::test_mailparse_stream_encode() { { String text = "hello, this is some text=hello."; Variant fp = f_tmpfile(); f_fwrite(fp, text); f_rewind(fp); Variant dest = f_tmpfile(); f_mailparse_stream_encode(fp, dest, "quoted-printable"); f_rewind(dest); Variant data = f_fread(dest, 2048); VS(data, "hello, this is some text=3Dhello."); } { String text = "To: [email protected]\n" "\n" "blah blah blah From blah $ \" & £ blah blah blah blah blah\n" "From the first of the month, things will be different!\n" "blah blah blah From blah\n" "Frome is a town in Somerset."; f_ob_start(); Variant fp = f_tmpfile(); f_fwrite(fp, text); f_rewind(fp); Variant fpdest = f_tmpfile(); f_mailparse_stream_encode(fp, fpdest, "quoted-printable"); f_rewind(fpdest); f_fpassthru(fpdest); f_fclose(fp); f_fclose(fpdest); String output = f_ob_get_contents(); f_ob_end_clean(); VS(output, "To: [email protected]\r\n" "\r\n" "blah blah blah From blah $ \" & =C2=A3 blah blah blah blah blah\r\n" "=46rom the first of the month, things will be different!\r\n" "blah blah blah From blah\r\n" "Frome is a town in Somerset."); } return Count(true); }
bool TestExtFile::test_rewind() { Variant f = f_fopen("test/test_ext_file.tmp", "w"); f_fputs(f, "testing rewind"); f_fclose(f); f = f_fopen("test/test_ext_file.tmp", "r"); VS(f_fread(f, 7), "testing"); VS(f_fread(f, 100), " rewind"); VS(f_fread(f, 7), ""); VERIFY(f_rewind(f)); VS(f_fread(f, 7), "testing"); VS(f_fread(f, 100), " rewind"); return Count(true); }
bool TestExtMailparse::test_mailparse_msg_extract_part() { String text = "To: [email protected]\n" "Mime-Version: 1.0\n" "Content-Type: text/plain\n" "Subject: A simple MIME message\n" "\n" "hello, this is some text hello.\n" "blah blah blah.\n"; Variant fp = f_tmpfile(); f_fwrite(fp, text); f_rewind(fp); f_ob_start(); Variant mime = f_mailparse_msg_create(); f_mailparse_msg_parse(mime, text); echo("Extract to output\n"); f_mailparse_msg_extract_part_file(mime, fp); echo("Extract and return as string\n"); Variant result = f_mailparse_msg_extract_part_file(mime, fp, uninit_null()); echo("-->\n"); echo(result); echo("\nExtract to open file\n"); Variant fpdest = f_tmpfile(); f_mailparse_msg_extract_part_file(mime, fp, fpdest); echo("\nrewinding\n"); f_rewind(fpdest); f_fpassthru(fpdest); echo("\nExtract via user function\n"); f_mailparse_msg_extract_part_file(mime, fp); echo("\nExtract whole part to output\n"); f_mailparse_msg_extract_whole_part_file(mime, fp); echo("\nExtract part from string to output\n"); f_mailparse_msg_extract_part(mime, text); f_fclose(fpdest); f_fclose(fp); String output = f_ob_get_contents(); f_ob_end_clean(); VS(output, "Extract to output\n" "hello, this is some text hello.\n" "blah blah blah.\n" "Extract and return as string\n" "-->\n" "hello, this is some text hello.\n" "blah blah blah.\n" "\n" "Extract to open file\n" "\n" "rewinding\n" "hello, this is some text hello.\n" "blah blah blah.\n" "\n" "Extract via user function\n" "hello, this is some text hello.\n" "blah blah blah.\n" "\n" "Extract whole part to output\n" "To: [email protected]\n" "Mime-Version: 1.0\n" "Content-Type: text/plain\n" "Subject: A simple MIME message\n" "\n" "hello, this is some text hello.\n" "blah blah blah.\n" "\n" "Extract part from string to output\n" "hello, this is some text hello.\n" "blah blah blah.\n"); return Count(true); }
FUNCTION static CODE tut_h_prep ( struct CONTXT *pctx, /* in: proc context */ struct SFILE *hf, /* in/out: help file */ struct TXTSTOR *title /* out: blodk of .TITLE text */ ) { IMPORT struct VARIABLE *char_gbl; /* system characteristics */ struct CONTXT *ctx; TEXT libe[FLIBRSIZ+1]; struct DIRBLK db; /* directive ctrl blk for d_ package */ struct CP_HEADER header; /* compiled PDF header record */ COUNT recsize; CODE code; TEXT field[STRINGSIZ+1]; TEXT dirtyp[STRINGSIZ+1]; TEXT ttlmsg[STRINGSIZ+1]; TEXT ttlkey[STRINGSIZ+1]; for (ctx = pctx; (s_equal((*ctx).pdf.libr,"/LOCAL/")); ctx = (*ctx).backlink); s_copy ((*ctx).pdf.libr, libe); d_init(&db, hf, libe, (TEXT **) (*char_gbl).v_cvp, (*char_gbl).v_count); /* init directive block */ if ((*pctx).compiled) /* if compiled PDF */ { f_rewind(hf); f_read(hf, field); /* dummy read -- space to header*/ code = f_bread(hf, (GENPTR)&header, sizeof(struct CP_HEADER), &recsize); if (code != SUCCESS) goto read_err; if (header.type != C_HEADER) goto hdr_type_err; if (header.title.possav) /* if .TITLE text exists */ { f_setpos(hf, &header.title); /* position to .TITLE */ code = f_read(hf, field); /* read the .TITLE record */ if (code != SUCCESS) goto read_err; code = gettitle(&db, title, ttlmsg, ttlkey); if (code != SUCCESS) goto title_err; } if (header.help.possav) /* if .HELP text exists */ { MOVE_STRUCT(header.help, tutctx.hlppos); /* save .HELP posit */ tutctx.hlpexist = TRUE; } if (header.level2.possav) /* if .LEVEL2 help text exists */ { f_setpos(hf, &header.level2); /* posit to .LEVEL2 */ f_read(hf, field); f_read(hf, field); /* dummy reads to pass .LEVEL2 */ f_movpos(&(*hf).posctx, &tutctx.lasth2pos); f_movpos(&(*hf).posctx, &tutctx.lev2start); tutctx.h2exist = TRUE; } if (header.level1.possav) /* if .LEVEL1 help text exists */ { f_setpos(hf, &header.level1); /* posit to .LEVEL1 */ f_read(hf, field); f_read(hf, field); /* dummy reads to pass .LEVEL1 */ f_movpos(&(*hf).posctx, &tutctx.lasth1pos); /* save as last level 1 help posit*/ f_movpos(&(*hf).posctx, &tutctx.lev1start); /* & permanently as start of .LEVEL section*/ tutctx.h1exist = TRUE; } tutctx.nohelpf= !tutctx.hlpexist && !tutctx.h1exist && !tutctx.h2exist; } else /* not in compiled PDF */ { while ((code = d_dirctv(&db, dirtyp, field)) == SUCCESS) { if (s_equal(dirtyp, ".TITLE")) /* if .TITLE text present */ { if (gettitle(&db, title, ttlmsg, ttlkey) != SUCCESS) goto title_err; } else if (s_equal(dirtyp, ".HELP")) { f_movpos(&(*hf).posctx, &tutctx.hlppos); /* save .HELP posit*/ tutctx.hlpexist = TRUE; } else if (s_equal(dirtyp, ".LEVEL1")) { f_read(hf, field); /* dummy read to get past .LEVEL1 */ f_movpos(&(*hf).posctx, &tutctx.lasth1pos); /* save as last level 1 help posit*/ f_movpos(&(*hf).posctx, &tutctx.lev1start); /* & permanently as start of .LEVEL section*/ tutctx.h1exist = TRUE; break; } else if (s_equal(dirtyp, ".LEVEL2")) { f_read(hf, field); /* dummy read to get past .LEVEL2 */ f_movpos(&(*hf).posctx, &tutctx.lasth2pos); f_movpos(&(*hf).posctx, &tutctx.lev2start); tutctx.h2exist = TRUE; } else if (s_equal(dirtyp, ".END")) { tutctx.nohelpf= !tutctx.hlpexist && !tutctx.h1exist && !tutctx.h2exist; break; } else goto struct_err; /* otherwise badly structured help file */ } if (code != SUCCESS) goto dir_err; } return(SUCCESS); title_err: tutmsg(ttlmsg, ttlkey, 0, 0, 0, 0, 0); /* help file title read error */ goto close_err; struct_err: tutmsg("Unrecognized directive '%s' in help file.", "TAE-BADHLPDIR", (uintptr_t) dirtyp, 0, 0, 0, 0); fretxt(title); goto close_err; dir_err: tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0); /* help file read error */ fretxt(title); goto close_err; read_err: tutmsg(msg_hrde, key_hrde, (uintptr_t) (*pctx).pdf.name, 0, 0, 0, 0); /* help file read error */ goto close_err; hdr_type_err: tutmsg("Compiled PDF has bad header record.", "TAE-CPDFBHDR", 0, 0, 0, 0, 0); goto close_err; close_err: return(FAIL); }
FUNCTION CODE old_Co_ReadFile ( Id c, /* in: existing collection */ TEXT *filespec, /* in: name of file to read */ CODE mode /* in: mode for the vm objs */ ) { struct SFILE f; union { struct PARHDR ph; /* standard header */ TEXT padding[300]; /* in case reading new file */ } headBuffer; CODE code; COUNT recsize; Id vm; TEXT record [STRINGSIZ+2]; BOOL archive; TEXT fullSpec[STRINGSIZ+1]; struct FSBLOCK fsblock; /* to dig out file name */ TEXT errstr[STRINGSIZ+1]; COUNT islash; #ifdef UNIX union { TEXT record [STRINGSIZ+1]; /* padding for long records */ struct ar_hdr header; /* the real archive header */ } hdrRecord; #endif code = f_opnspc (&f, 1, filespec, "", "", "res", F_READ); if (code != SUCCESS) { x_error(mode, "Unable to open resource file '%s'. %s.", "TAE-PFOPN", (uintptr_t)filespec, (uintptr_t)f.errmsg, 0); return (FAIL); } /* determine whether file is concatenated or archive format */ code = f_read (&f, record); if (code == SUCCESS && s_equal (record, AR_SENTINEL)) archive = TRUE; else { archive = FALSE; f_rewind (&f); /* re-start at beginning */ } /* read each Vm object from the file */ while (FOREVER) { if (archive) /* skip header */ { #ifdef UNIX code = f_read (&f, (TEXT *)&hdrRecord); /* read hdr or pad */ if (code == SUCCESS && hdrRecord.record[0] == EOS) code = f_read (&f, (TEXT *)&hdrRecord); /* skip EOF padding */ if (code == F_EOF) { code = SUCCESS; break; } else if (code != SUCCESS) { f_close(&f, F_KEEP); x_error (mode, "File '%s' not correctly formatted.", "TAE-RESFORMAT", (uintptr_t)filespec, 0, 0); return (FAIL); } #ifdef AIX s_bcopy (hdrRecord.header._ar_name.ar_name, fullSpec, sizeof(hdrRecord.header._ar_name.ar_name)); #else s_bcopy (hdrRecord.header.ar_name, fullSpec, sizeof(hdrRecord.header.ar_name)); #endif s_strip (fullSpec); /* remove trailing blanks */ islash = s_index (fullSpec, '/'); /* HP (and others?) */ if (islash >= 0) /* term with slash */ fullSpec[islash] = EOS; /* clip at slash */ f_crack (fullSpec, "", "", "", &fsblock, errstr); /* dig name */ #else x_error (mode, "File '%s' not correctly formatted.", "TAE-RESFORMAT", filespec, 0, 0); return (FAIL); #endif } code = f_bread (&f, (GENPTR)&headBuffer, sizeof (headBuffer), &recsize); if (code == F_EOF) { code = SUCCESS; /* normal end-of-file */ break; } else if (code == SUCCESS && s_equal (headBuffer.ph.sentinel, "<<new par-file>>")) { f_close(&f, F_KEEP); x_error(mode, "Resource file '%s' has already been converted.", "TAE-VNEWFORMAT", (uintptr_t)filespec, 0, 0); return (FAIL); } else if(code != SUCCESS || !s_equal(headBuffer.ph.sentinel, P_SENTINEL)) { f_close(&f, F_KEEP); x_error(mode, "Error reading resource file '%s'. %s.", "TAE-PFRD", (uintptr_t)filespec, (uintptr_t)f.errmsg, 0); return (FAIL); } vm = Vm_New (mode); /* create new vm object */ code = Vm_ReadVm ((struct VM_STRUCT *)vm, &f); /* read parblk records */ if (code != SUCCESS) break; /* x_error already called */ if (archive) old_Co_Add ((struct COLLECTION *)c, vm, fsblock.name, C_VM); else old_Co_Add ((struct COLLECTION *)c, vm, headBuffer.ph.filename, C_VM); } f_close (&f, F_KEEP); return (code); }