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

📄 readpart.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 3 页
字号:
{//// Loop through the list of icons and see which one corresponds to this//    window//   PtrListC&	list  = This->msgBodyText->GraphicList();   u_int	count = list.size();   for (int i=0; i<count; i++) {      ReadIconC	*icon = (ReadIconC*)*list[i];      if ( icon->msgWin == win ) {	 icon->msgWin = NULL;	// So it doesn't get hidden again	 This->HideIcon(icon);	 return;      }   }} // End HideMsgWin/*----------------------------------------------------------------------- *  Handle request for hide of mime part */voidReadWinP::DoHidePart(Widget, ReadWinP *This, XtPointer){   This->HideIcon(This->popupIcon);}/*----------------------------------------------------------------------- *  Method to hide the window for a mime attachment */voidReadWinP::HideIcon(ReadIconC *icon){   if ( icon->textWin ) {      LocalTextWinC	*win = icon->textWin;      icon->textWin = NULL;      win->Hide();   }   if ( icon->msgWin ) {      ReadWinC	*win = icon->msgWin;      icon->msgWin = NULL;      win->Hide();   }//// See if there is an external display process//   DisplayDataT	*data = DisplayData(icon);   if ( data && data->pid > 0 )      if ( kill(-data->pid, 0) == 0 ) kill(-data->pid, SIGKILL);   icon->AnimationOff();   icon->Unhighlight();} // End HideIcon/*----------------------------------------------------------------------- *  Handle request for save of mime part */voidReadWinP::DoSavePart(Widget, ReadWinP *This, XtPointer){   MsgPartC	*part = This->popupIcon->part;   This->pub->ClearMessage();//// See if this part needs to be retrieved first//   if ( part->NeedFetch() && !This->OkToGet(part, "getString") ) return;   if ( !This->savePartWin ) {      This->pub->BusyCursor(True);      This->savePartWin = new FileChooserWinC(*This->pub, "savePartWin");      This->savePartWin->AddOkCallback((CallbackFn*)FinishSavePart, This);      This->savePartWin->SingleSelect(True);      This->savePartWin->HideList();      This->savePartWin->SetDirectory(".");      This->savePartWin->SetDefaultDir(".");      This->savePartWin->ShowDirsInFileList (False);      This->savePartWin->ShowFilesInFileList(True);      This->savePartWin->HideImap();      This->pub->BusyCursor(False);   }   ParamC	*param = part->Param("filename", part->disParams);   if ( !param ) param = part->Param("name",     part->disParams);   if ( !param ) param = part->Param("name",     part->accParams);   if ( !param ) param = part->Param("name");   if ( param )      TextFieldSetString(This->savePartWin->SelectTF(), param->val);   This->savePartWin->Show();} // End DoSavePart/*----------------------------------------------------------------------- *  Callback to handle ok of mime part save with filename */voidReadWinP::FinishSavePart(StringListC *list, ReadWinP *This){   This->savePartWin->HideOk(True);//// See if the name is OK//   StringC	*nameStr = (*list)[0];   switch ( OverwriteQuery(*nameStr, *This->pub) ) {      case (QUERY_YES):	 break;      case (QUERY_NO):      case (QUERY_NONE):	 if ( debuglev > 0 ) cout <<"Didn't want to overwrite" NL;	 This->savePartWin->HideOk(False);	 return;      case (QUERY_CANCEL):	 if ( debuglev > 0 ) cout <<"Operation cancelled" NL;	 return;   } // End switch OverwriteQuery//// See if the part needs to be retrieved first.  We've already asked the user//    if this is ok.//   MsgPartC	*part = This->popupIcon->part;   if ( part->NeedFetch() )      This->FetchPart(This->popupIcon, *nameStr, (CallbackFn*)SaveAfterFetch);   else      This->SavePart(This->popupIcon, *nameStr);} // End FinishSavePart/*----------------------------------------------------------------------- *  Finish request for save of MIME attachment.  This one is called *     after a fetch completes */voidReadWinP::SaveAfterFetch(ReadIconC *icon, ReadWinP*){//// We fetched directly to the destination so this is all we have to do//   icon->part->delDataFile = False;}/*----------------------------------------------------------------------- *  Finish request for save of MIME attachment.  This one is called *     when file is already available */voidReadWinP::SavePart(ReadIconC *icon, const char *name){   pub->BusyCursor(True);//// Create the file and any directories that might be needed//   if ( !MakeFile(name) ) return;   StringC	body;   icon->part->GetData(body);   StringC	statmsg;   if ( !body.WriteFile((char*)name) ) {      int	err = errno;      statmsg = "Could not save to file: ";      statmsg += name;      statmsg += ".\n";      statmsg += SystemErrorMessage(err);      pub->PopupMessage(statmsg);      pub->BusyCursor(False);      return;   }   statmsg = "Part ";   statmsg += icon->part->partNum;   statmsg += " saved to file: ";   statmsg += name;   pub->Message(statmsg);   pub->BusyCursor(False);} // End SavePart/*----------------------------------------------------------------------- *  Handle request for print of mime part */voidReadWinP::DoPrintPart(Widget, ReadWinP *This, XtPointer){   MsgPartC	*part = This->popupIcon->part;   This->pub->ClearMessage();//// See if this part needs to be retrieved first//   if ( part->NeedFetch() ) {//// Ask the user is this is OK//      if ( !This->OkToGet(part, "getString") ) return;      This->FetchPart(This->popupIcon, NULL, (CallbackFn*)FinishPrintPart);   }   else      FinishPrintPart(This->popupIcon, This);} // End DoPrintPart/*----------------------------------------------------------------------- *  Finish request for print of MIME attachment.  This one is called *     after we know the file is present. */voidReadWinP::FinishPrintPart(ReadIconC *icon, ReadWinP *This){   MsgPartC	*part = icon->part;//// Get the part into an external file//   if ( !part->CreateDataFile() ) return;//// Get the mailcap entry//   StringC	cmdStr;   MailcapC	*mcap = MailcapEntry(part);   if ( mcap && mcap->print.size() > 0 ) cmdStr = mcap->print;   else					 cmdStr = ishApp->appPrefs->printCmd;//// Create some callback data//   PrintDataT	*data = new PrintDataT;   data->win    = This;   data->part   = part;   data->cmdStr = BuildCommand(cmdStr, part, part->dataFile);   CallbackC	doneCb((CallbackFn*)PrintDone, data);   data->pid = ForkIt(data->cmdStr, &doneCb);   if ( data->pid < 0 ) {      StringC	errmsg = "Could not print part ";      errmsg += part->partNum;      errmsg += "\n" + ForkStatusMsg(data->cmdStr, (int)data->pid);      This->pub->PopupMessage(errmsg);      delete data;   }   else {      StringC	statmsg("Part ");      statmsg += part->partNum;      statmsg += " sent to printer.";      This->pub->Message(statmsg);   }} // End FinishPrintPart/*--------------------------------------------------------------- *  Callback for completion of ForkIt print job */voidReadWinP::PrintDone(int status, PrintDataT *data){   if ( debuglev > 0 ) cout <<"Print process finished" <<endl;   ReadWinP	*This = data->win;   MsgPartC	*part = data->part;//// Report status of operation//   if ( status != 0 ) {      StringC	errmsg("Part ");      errmsg += part->partNum;      errmsg += " could not be printed:\n";      errmsg += ForkStatusMsg(data->cmdStr, status, data->pid);      This->pub->PopupMessage(errmsg);   } // End if there is an error   if ( data->file.size() > 0 ) {      if ( debuglev > 0 ) cout <<"Unlinking temp file" <<endl;      unlink(data->file);   }   delete data;} // End PrintDone/*----------------------------------------------------------------------- *  Handle request for fetch of mime part */voidReadWinP::DoFetchPart(Widget, ReadWinP *This, XtPointer){   This->FetchPart(This->popupIcon, NULL, (CallbackFn*)NULL);}voidReadWinP::FetchPart(ReadIconC *icon, const char *filename, CallbackFn *doneCall){   MsgPartC	*part   = icon->part;   Boolean	doFetch = True;   icon->Highlight();//// If we've already done a fetch, see if the user wants to do it again//   if ( !part->NeedFetch() )      doFetch = OkToGet(part, "getAgainString");   if ( !doFetch ) {      icon->Unhighlight();      return;   }//// Prompt for user name and password if necessary//   if ( part->IsFTP() && part->userName.size() == 0 ) {//// Look up the ftp address//      ParamC	*site = part->Param("site");      if ( !site ) {	 StringC errmsg("The FTP site name was not specified for file: ");	 part->GetFileName(errmsg);	 errmsg += ".\nThe file could not be retrieved.";	 pub->PopupMessage(errmsg);	 icon->Unhighlight();	 return;      }//// Prompt for login//      if ( !loginWin ) loginWin = new LoginWinC(*pub);      if ( !loginWin->GetLogin(site->val, part->userName, part->userPass) ) {	 icon->Unhighlight();	 return;      }   } // End if login is needed//// For security reasons, confirm retrieval of mail-server attachments.// We don't want someone sending an attachment that will cause someone//   else to send obnoxious mail.//   if ( part->IsMail() ) {      if ( !OkToSend(part) ) {	 icon->Unhighlight();	 return;      }   }//// Look for a mailcap entry for message/external-body//   MailcapC	*mcap = MailcapEntry(MESSAGE_S, EXTERNAL_BODY_S, part);   if ( !mcap ) {      StringC errmsg = "I could not find a mailcap entry for: ";      errmsg += "message/external-body.";      errmsg += ".\nThe file could not be retrieved.";      pub->PopupMessage(errmsg);      icon->Unhighlight();      return;   }//// See if there's a fetch command//   if ( mcap->present.size() == 0 ) {      StringC errmsg = "The mailcap entry for message/external-body does ";      errmsg += "not specify a command for getting the file.";      errmsg += ".\nThe file could not be retrieved.";      pub->PopupMessage(errmsg);      icon->Unhighlight();      return;   }//// Clear out the old external file name//   if ( part->delDataFile && part->dataFile.size() > 0 ) {      unlink(part->dataFile);      part->dataFile.Clear();      part->delDataFile = False;   }//// Create a new name for the external file//   StringC	file;   if ( filename )      file = filename;   else {      char	*cs = tempnam(NULL, "ext.");      file = cs;      free(cs);   }//// If this is a mail server attachment, write the commands to the temp file//   if ( part->IsMail() ) {      StringC	body;      part->GetText(body);      if ( !body.WriteFile(file) ) {	 StringC errmsg = "Could not write file \"";	 errmsg += file;	 errmsg += "\" to send to mail server.\n";	 errmsg += SystemErrorMessage(errno);	 errmsg += ".\nThe file could not be retrieved.";	 pub->PopupMessage(errmsg);	 icon->Unhighlight();	 return;      }   } // End if mail server//// Build a data record to store info about this fetch//   FetchDataT	*data = new FetchDataT;   data->win  = this;   data->icon = icon;   data->part = part;   data->file = file;   data->postFetchCall.Set(doneCall, (void*)this);//// Build the command for retrieval.  The present command is used since this//   is a message/external-body type.//   data->cmdStr = BuildCommand(mcap->present, part, file);   data->pid    = -1;   CallbackC	doneCb((CallbackFn*)FetchDone, data);   data->pid = ForkIt(data->cmdStr, &doneCb);//// If the pid is < 0, an error occurred//   if ( data->pid < 0 ) {      pub->PopupMessage(ForkStatusMsg(data->cmdStr, (int)data->pid));      icon->Unhighlight();      delete data;   }//// Add this process to the list of running processes//   else {      void	*tmp = (void*)data;      fetchDataList->add(tmp);//// Start the retrieval animation//      LoadFetchPixmaps(icon);      icon->Animate(fetchPixmaps);   }} // End FetchPart/*--------------------------------------------------------------- *  Callback called when retrieval process stops */voidReadWinP::FetchDone(int status, FetchDataT *data){   ReadWinP	*This = data->win;//// Remove this data from the list of active fetches//   void	*tmp = (void*)data;   fetchDataList->remove(tmp);//// Make sure the icon is still around//   ReadIconC	*icon = data->icon;   PtrListC&	list  = This->msgBodyText->GraphicList();   u_int	count = list.size();   Boolean	found = False;   for (int i=0; !found && i<count; i++) {      ReadIconC	*ip = (ReadIconC*)*list[i];      found = (ip == icon);   }   MsgPartC	*part = data->part;   StringC	name;   part->GetFileName(name);   if ( debuglev > 0 ) cout <<"FetchDone for file: " <<name <<endl;//// Turn off the retrieval animation//   if ( found ) icon->AnimationOff();//// Report status if reading window is no longer visible or if the message//    has changed or if this is a mail server attachment that we don't yet//    have.//   if ( !This->pub->IsShown() || This->pub->msg != part->parentMsg ||        status != 0 || part->IsMail() ) {      StringC	statmsg("File \"");      statmsg += name;      if ( status != 0 ) {	 statmsg += "\" could not be retrieved.\n";	 statmsg += ForkStatusMsg(data->cmdStr, status, data->pid);      }      else if ( part->IsMail() )	 statmsg += "\" will arrive by mail at a later time.";

⌨️ 快捷键说明

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