⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printwinc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 4 页
字号:
   } // End if a single message//// Report status//   if ( printed || This->cancelled ) {      if ( !This->cancelled )	 ishApp->Broadcast(statusMsg);      This->Hide();   }} // End DoPrint/*--------------------------------------------------------------- *  Method to handle print of a single normal message */BooleanPrintWinC::Print(MsgC *msg){   BusyCursor(True);   MsgItemC	*item = msg->icon;   int	msgnum = msg->Number();//// Create a temporary file for the message//   char	*tmpFile = tempnam(NULL, "prnt.");   if ( !tmpFile ) {      int	err = errno;      StringC	errmsg = "Couldn't create temp file while printing message: ";      if ( msgnum >= 0 ) errmsg += msgnum;      errmsg += ".\n" + SystemErrorMessage(err);      if ( IsShown() ) PopupMessage(errmsg);      else	       halApp->PopupMessage(errmsg);      BusyCursor(False);      return False;   }//// Write the message to the temp file//   if ( !msg->WriteFile(tmpFile, !XmToggleButtonGetState(hdrNoneTB),			XmToggleButtonGetState(hdrAllTB),			False/*no status header*/,			False/*no blank line*/, False/*don't protect Froms*/) )   {      unlink(tmpFile);      free(tmpFile);      BusyCursor(False);      return False;   }   Boolean printed = PrintFile(tmpFile, PRINT_PLAIN, True, msgnum);   if ( printed ) {      if ( item ) item->SetPrinted();      else	  msg->SetPrinted();   }   BusyCursor(False);   return printed;} // End Print/*--------------------------------------------------------------- *  Method to handle print of a single MIME message */BooleanPrintWinC::PrintMime(MsgC *msg){   BusyCursor(True);   PtrListC	sepList;   MsgItemC	*item = msg->icon;   int	msgnum = msg->Number();//// Create a temporary file for storing messages//   char	*tmpFile = tempnam(NULL, "prnt.");   if ( !tmpFile ) {      int	err = errno;      StringC	errmsg = "Couldn't create temp file while printing message: ";      if ( item ) errmsg += msgnum;      errmsg += ".\n" + SystemErrorMessage(err);      BusyCursor(False);      if ( IsShown() ) PopupMessage(errmsg);      else	       halApp->PopupMessage(errmsg);      return False;   }   FILE *tfp = fopen(tmpFile, "w+");   if ( !tfp ) {      int	err = errno;      StringC	errmsg = "Couldn't create temp file while printing message: ";      if ( item ) errmsg += msgnum;      errmsg += ".\n" + SystemErrorMessage(err);      free(tmpFile);      BusyCursor(False);      if ( IsShown() ) PopupMessage(errmsg);      else	       halApp->PopupMessage(errmsg);      return False;   }//// Determine what text type will be used to print//   PrintTypeT	pType = PRINT_PLAIN;   MsgPartC	*body = msg->Body();   if      ( ContainsEnriched(body) ) pType = PRINT_ENRICHED;   else if ( ContainsRich    (body) ) pType = PRINT_RICH;//// Write headers//   Boolean	printed = PrintHeaders(msg, tfp, pType);//// Add each text part of the message to the file.//   if ( printed ) {      printed = PrintText(body, tfp, sepList, pType);      if ( cancelled ) {	 fclose(tfp);	 if ( debuglev > 0 ) cout <<"Unlinking temp file" <<endl;	 unlink(tmpFile);	 free(tmpFile);	 BusyCursor(False);	 return False;      }   }//// Check for errors//   if ( !printed ) {      int	err = errno;      StringC	errmsg = "Couldn't write to temp file while printing message: ";      if ( item ) errmsg += msgnum;      errmsg += ".\n" + SystemErrorMessage(err);      fclose(tfp);      if ( debuglev > 0 ) cout <<"Unlinking temp file" <<endl;      unlink(tmpFile);      free(tmpFile);      BusyCursor(False);      if ( IsShown() ) PopupMessage(errmsg);      else	       halApp->PopupMessage(errmsg);      return False;   }   fclose(tfp);//// Print the temp file.  This routine will also delete it.//   printed = PrintFile(tmpFile, pType, True, msgnum);   if ( !printed ) {      BusyCursor(False);      return False;   }//// Now make a pass and print the separate parts//   unsigned	count = sepList.size();   for (int i=0; !cancelled && i<count; i++) {      MsgPartC	*part = (MsgPartC*)*sepList[i];      PrintNonText(part);   }   if ( item ) item->SetPrinted();   else	       msg->SetPrinted();   BusyCursor(False);   return True;} // End PrintMime/*--------------------------------------------------------------- *  Method to print selected headers for given message */BooleanPrintWinC::PrintHeaders(MsgC *msg, FILE *fp, PrintTypeT pType){   if ( XmToggleButtonGetState(hdrNoneTB) ) return True;   Boolean	success = True;   if ( pType == PRINT_PLAIN ) {      success = msg->WriteHeaders(fp, XmToggleButtonGetState(hdrAllTB), False);   }   else {//// Read headers into a string so they can be richified//      StringC	headStr;      Boolean	all = XmToggleButtonGetState(hdrAllTB);      HeaderC	*head  = msg->Headers();      Boolean	needNL = False;      while ( head ) {//// See if this header should be printed//	 if ( all || ishApp->headPrefs->HeaderShown(head->key) ) {	    if ( needNL ) headStr += '\n';	    headStr += head->key;	    headStr += ": ";	    head->GetValueText(headStr);	    needNL = True;	 } // End if header is displayed	 head = head->next;      } // End for each header      if ( headStr.size() > 0 ) {	 headStr += '\n';	 if      ( pType == PRINT_ENRICHED ) MakeEnriched(headStr);	 else if ( pType == PRINT_RICH     ) MakeRich(headStr);	 success = headStr.WriteFile(fp);      }   } // End if not printing as plain text   return success;} // End PrintHeaders/*--------------------------------------------------------------- *  Method to look for plaintext parts and print them */BooleanPrintWinC::PrintText(MsgPartC *part, FILE *fp, PtrListC& sepList,		     PrintTypeT pType, Boolean doNext){   if ( !part ) return True;   if ( debuglev > 0 ) cout <<"Checking " <<part->conStr <<endl;   Boolean	printed = False;   if ( part->IsMultipart() ) {//// If this is an alternative, find the best choice.  If it is text, print it.//      if ( part->IsAlternative() ) {	 MsgPartC	*child = part->BestAlternative(True/*forPrinting*/);	 printed = PrintText(child, fp, sepList, pType, False/*doNext*/);      }//// If this is not an alternative, print all the children, starting with//    the first//      else	 printed = PrintText(part->child, fp, sepList, pType);   } // End if multipart         else if ( !part->IsExternal() && part->IsText() ) {      StringC	partStr;      part->GetData(partStr);      if ( pType == PRINT_ENRICHED ) {	 if ( part->IsPlainText() ) MakeEnriched(partStr);	 if ( !partStr.EndsWith("\n") ) partStr += "\n";      }      else if ( pType == PRINT_RICH ) {	 if ( part->IsPlainText() ) MakeRich(partStr);	 while ( partStr.EndsWith("\n") ) partStr.Clear(partStr.size()-1);	 if ( !partStr.EndsWith("<nl>") ) partStr += "<nl>\n";      }      printed = partStr.WriteFile(fp);   }   else {      printed = InsertMessage(part, fp, sepList, pType);   }   if ( doNext && !cancelled && part->next )      printed = PrintText(part->next, fp, sepList, pType);   return (printed && !cancelled);} // End PrintText/*--------------------------------------------------------------- *  Method to look for non-text parts and print them */BooleanPrintWinC::PrintNonText(MsgPartC *part){//// Retrieve the part if necessary//   if ( part->IsExternal() && (!GetPart(part) || cancelled) )      return False;//// If this is an rfc822 message, pass it back through the top level routines//   if ( part->Is822() ) {      FileMsgC	*msg822 = part->ChildMsg();      Boolean	printed = False;      if ( msg822->IsMime() ) printed = PrintMime(msg822);      else                    printed = Print(msg822);      return printed;   } // End if printing an rfc822 message//// See if this type can be printed//   MailcapC	*mcap    = MailcapEntry(part);   Boolean	canPrint = ((mcap && mcap->print.size() > 0) ||			    (part->IsText() || part->IsPostScript()));   if ( !canPrint ) return False;   //// Use the part data file//   if ( !part->CreateDataFile() ) return False;//// See how this part is to be printed//   if ( mcap && mcap->print.size() > 0 ) {//// Create some callback data//      PrintProcT	*proc = new PrintProcT;      proc->win    = this;      proc->msgnum = -1;      proc->cmdStr = BuildCommand(mcap->print, part, part->dataFile);      CallbackC	doneCb((CallbackFn*)PrintDone, proc);      proc->pid = ForkIt(proc->cmdStr, &doneCb);      if ( proc->pid < 0 ) {	 StringC	errmsg = "Could not print ";	 part->GetLabel(errmsg);	 errmsg += "\n" + ForkStatusMsg(proc->cmdStr, (int)proc->pid);	 if ( IsShown() ) PopupMessage(errmsg);	 else		  halApp->PopupMessage(errmsg);	 delete proc;	 return False;      }   }   else {	// Must be text      PrintTypeT	pType = PRINT_PLAIN;      if ( part->IsEnriched() ) pType = PRINT_ENRICHED;      if ( part->IsRichText() ) pType = PRINT_RICH;      if ( !PrintFile(part->dataFile, pType, False) ) return False;   } // End if no mailcap entry   return True;} // End PrintNonText/*--------------------------------------------------------------- *  Method to insert a message about a part that can't be printed or *     will be printed separately */BooleanPrintWinC::InsertMessage(MsgPartC *part, FILE *fp, PtrListC& sepList,			 PrintTypeT pType){   StringC		str;   StringC		typeStr;   Boolean		printable = False;   Boolean		okToPrint = True;   StringC		name;   part->GetFileName(name);   if      ( pType == PRINT_ENRICHED ) str = "\n\n<center>";   else if ( pType == PRINT_RICH     ) str = "<nl>\n<center>";   else				       str = "\n\t";   typeStr = part->conStr;   MailcapC	*mcap = MailcapEntry(part);   printable = (mcap && mcap->print.size()>0);   if ( part->IsExternal() ) {      if      ( part->IsPlainText() ) {	 typeStr = "Text";	 printable = True;      }      else if ( part->IsEnriched() ) {	 typeStr = "EnrichedText";	 printable = True;      }      else if ( part->IsRichText() ) {	 typeStr = "RichText";	 printable = True;      }      else if ( part->Is822() ) {	 typeStr = "Mail Message";	 printable = True;      }      else if ( part->IsPostScript() ) {	 typeStr = "PostScript";	 printable = True;      }      else if ( part->IsBinary()     ) typeStr = "Binary";      else if ( part->IsGIF()        ) typeStr = "GIF Image";      else if ( part->IsJPEG()       ) typeStr = "JPEG Image";      else if ( part->IsMPEG()       ) typeStr = "MPEG Video";      else if ( part->IsBasicAudio() ) typeStr = "U-LAW Audio";      str += "(Attached ";      str += typeStr;      str += " File: ";      str += name;      str += ')';//// If this part can be printed and hasn't been retrieved, see if the user//    wants it retrieved.  If it has been retrieved, see if the user//    wants it printed.//      if ( printable ) {	 if ( part->NeedFetch() ) okToPrint = OkToGet(part);	 else			  okToPrint = OkToPrint(part);      }   } // End if part is external         else {      Boolean	confirmPrint = True;      if ( part->Is822() ) {	 typeStr = "Mail Message";	 printable = True;	 confirmPrint = False;	 FileMsgC	*msg = part->ChildMsg();	 msg->GetSubjectText(name);      }      else if ( part->IsPostScript() ) {	 typeStr = "PostScript File";	 printable = True;	 confirmPrint = False;      }      else if ( part->IsBinary()     ) typeStr = "Binary";      else if ( part->IsGIF()        ) typeStr = "GIF Image";      else if ( part->IsJPEG()       ) typeStr = "JPEG Image";      else if ( part->IsMPEG()       ) typeStr = "MPEG Video";      else if ( part->IsBasicAudio() ) typeStr = "U-LAW Audio";      str += "(Included ";      str += typeStr;      str += ": ";      str += name;      str += ')';//// See if the user wants this part printed//      if ( printable && confirmPrint )	 okToPrint = OkToPrint(part);   } // End if part is not external   if ( cancelled ) return False;   if      ( pType == PRINT_ENRICHED ) str += "\n\n";   else if ( pType == PRINT_RICH     ) str += "<nl>\n";   else				       str += "\n\t";//// Figure out if the message will be printed or not//   if ( printable ) {      if ( okToPrint ) {	 str += "(Printed separately)";	 void	*tmp = (void *)part;	 sepList.add(tmp);      }      else	 str += "(Not printed)";   } else      str += "(Not printable)";   if      ( pType == PRINT_ENRICHED ) str += "</center>\n\n";   else if ( pType == PRINT_RICH     ) str += "</center><nl>\n<nl>\n";   else				       str += "\n\n";   return str.WriteFile(fp);} // End InsertMessage/*--------------------------------------------------------------- *  Method to query user to see if part should be printed */BooleanPrintWinC::OkToPrint(MsgPartC *part){//// See if the user already answered.//   if ( !askAboutPrint ) return printAll;   static QueryAnswerT	answer;//

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -