HylaFAX The world's
most advanced open source fax server
|
|
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
Re: [hylafax-users] Text => Postscript converson in faxmail
* Aidan Van Dyk <aidan@xxxxxxxx> [071022 11:55]:
> > I think that all parts of a message (text/plain, text/html,
> > attachments) should be handled equaly; I'm not 100% sure how to best
> > deal with the headers/metainformation.
> >
> > A possible scenario could look like this:
> >
> > * create a postscript file using the internal converter containing only
> > meta-information from the email (headers, sender/recipient information,
> > whatever); submit as postscript file
> >
> > * treat all parts of a multipart/mime message, like attachments, i.e try
> > converting them based on typerules file and submit them as separate
> > documents.
> >
> > * I would love to have the added flexibility of the mimeconverters back:
> > for each part of the multipart message, first check if there's a
> > converter for the specified mime type. Use if it exists and try
> > converting via typerules if there's no converter.
>
> OK, so how about this:
>
> 1) Use internal formatter for "message/rfc822" (the main message starts
> this way) which prints headers, and the "body" if it's not a mime body,
> all as text (subject to the FormatEnvHeaders). Keep this as 1 document
> to submit to HylaFAX, with a option to suppress this document.
>
> 2) For every mime part, check for a mimeconverter program. The *output*
> of the mimeconverter program (if there is one) is submitted in place
> of the original mime part as a document to HylaFAX in the job through
> the normal machinery. Note that this means the output doesn't have
> to be Postscript/pdf/etc. It just needs to be something that the
> regular typerules based submission can convert to PS/PDF/TIFF if it
> isn't that directly. Having the mimeconverter program output be
> "empty" would mean that that mime part is not submitted as a
> document.
>
> 3) If no "mimeconverter" is found, handle the part directly.
> - multipart are recursively handled, as now
> - message/rfc are handle internally, as now
> - all others are submitted as separate documents, as now
>
> Would this framework be flexible enough for you? It fixes the main
> problems of faxmail (the squish everything into a single postscript
> document, and handling application/octet-stream), and gives back the
> flexibility of handling individual parts with special mechanisms.
Something like the following patch:
diff --git a/faxmail/faxmail.c++ b/faxmail/faxmail.c++
index 178d6de..ef3bd1e 100644
--- a/faxmail/faxmail.c++
+++ b/faxmail/faxmail.c++
@@ -95,6 +95,7 @@ private:
void formatApplication(FILE* fd, MIMEState& mime);
void formatDiscarded(MIMEState& mime);
void formatAttachment (FILE* fd, MIMEState& mime);
+ void formatWithExternal(FILE* fd, const char* app, MIMEState& mime);
void emitClientPrologue(FILE*);
@@ -448,7 +449,7 @@ faxMailApp::formatMIME(FILE* fd, MIMEState& mime, MsgFmt& msg)
/*
* Check first for any external script/command to
- * use in converting the body part to PostScript.
+ * use in converting the body part.
* If something is present, then we just decode the
* body part into a temporary file and hand it to
* the script. Otherwise we fallback on some builtin
@@ -456,7 +457,11 @@ faxMailApp::formatMIME(FILE* fd, MIMEState& mime, MsgFmt& msg)
* content types we expect to encounter.
*/
const fxStr& type = mime.getType();
- if (type == "text") {
+ fxStr app = mimeConverters | "/" | type | "/" | mime.getSubType();
+
+ if (Sys::access(app, X_OK) >= 0)
+ formatWithExternal(fd, app, mime);
+ else if (type == "text") {
if ( formatText(fd, mime) )
empty = false;
} else if (type == "application")
@@ -637,6 +642,24 @@ faxMailApp::formatAttachment(FILE* fd, MIMEState& mime)
}
/*
+ * Format a MIME part using an external conversion script.
+ * The output of this script is submitted as a document
+ */
+void
+faxMailApp::formatWithExternal (FILE* fd, const char* app, MIMEState& mime)
+{
+ if (verbose)
+ fprintf(stderr, "CONVERT: run %s\n", app);
+
+ fxStr tmp;
+ if ( copyPart(fd, mime, tmp)) {
+ runConverter(app, tmp, mime);
+ Sys::unlink(tmp);
+ }
+}
+
+
+/*
* Discard input data up to the next boundary marker.
*/
void
@@ -706,7 +729,6 @@ faxMailApp::runConverter(const fxStr& app, const fxStr& tmp, MIMEState& mime)
fxFatal("Couldn't open output file: %s", (const char*)output);
tmps.append(output);
- client->addFile(output);
const char* av[3];
av[0] = strrchr(app, '/');
@@ -735,7 +757,13 @@ faxMailApp::runConverter(const fxStr& app, const fxStr& tmp, MIMEState& mime)
int status;
close(fd);
if (Sys::waitpid(pid, status) == pid && status == 0)
+ {
+ struct stat sb;
+ Sys::stat(output, sb);
+ if (sb.st_size > 0)
+ client->addFile(output);
return (true);
+ }
error("Error converting %s/%s; command was \"%s %s\"; exit status %x"
, (const char*) mime.getType()
, (const char*) mime.getSubType()
--
Aidan Van Dyk aidan@xxxxxxxx
Senior Software Developer +1 215 825-8700 x8103
iFAX Solutions, Inc. http://www.ifax.com/
____________________ HylaFAX(tm) Users Mailing List _______________________
To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null
*To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*