if (mail_type=="sff"): # normal fax file # sff -> tif ret=os.spawnlp(os.P_WAIT,"sfftobmp","sfftobmp","-tif",attachment,basename+"tif") if (ret or not os.access(basename+"tif",os.F_OK)): raise "conv-error","Can't convert sff to tif. sfftobmp not installed?" # tif -> ps -> pdf # the first pipe must be handled by the shell so that the output of # of ps2pdf can be read immediately. Handling this shell in Python # leads to an overflow of the ps2pdf output pipe... command="tiff2ps -a "+escape(basename+"tif")+" | ps2pdf - -" tiff2pdf=popen2.Popen3(command) if (tiff2pdf.poll()!=-1): raise "conv-error","Error while calling tiff2ps or ps2pdf. Not installed?" tiff2pdf.tochild.close() # we don't need the input pipe # create attachment with pdf stream filepart = email.MIMEBase.MIMEBase("application","pdf",name=os.path.basename(basename)+"pdf") filepart.add_header('Content-Disposition','attachment',filename=os.path.basename(basename)+"pdf") filepart.set_payload(tiff2pdf.fromchild.read()) tiff2pdf.fromchild.close() ret=tiff2pdf.wait() if (ret!=0): raise "conv-error","Error "+str(ret)+" occured during tiff2ps or ps2pdf" os.unlink(basename+"tif") email.Encoders.encode_base64(filepart)