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

📄 sendiconc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------- *  Method to build a MIME message body for the specified type and file *     This will either be a multipart with no file or a text/plain with *     a file. */BooleanSendIconC::BuildPartFile(FILE *fp, char *type, char *ifile, char *ofile){   StringC	headStr;   data->dataFile = ifile;//// Build the content-type header for this body part//   headStr += "Content-Type: ";   headStr += type;   if ( headStr.Contains("multipart/") ) {       StringC	bound;       GenBoundary(bound);       AddQuotedVal(headStr, ";\n boundary=", bound);   }   headStr += '\n';//// Add a content-disposition header//   if ( ofile ) {      headStr += "Content-Disposition: attachment";      headStr += ";\n\tfilename=";      headStr += ofile;      headStr += '\n';   }//// Add a blank line//   while ( !headStr.EndsWith("\n\n") ) headStr += '\n';   if ( !headStr.WriteFile(fp) ) {      StringC	errmsg("Could not write file: \"");      errmsg += data->msgFile;      errmsg += "\".\n";      errmsg += SystemErrorMessage(errno);      sendWin->PopupMessage(errmsg);      return False;   }//// Add the body//   if ( ifile ) {      if ( !CopyFile(ifile, data->msgFile, False, False, NULL, fp) )	 return False;   }   return True;} // End BuildPartFile/*--------------------------------------------------------------- *  Method to build a MIME message body for the specified mail message */BooleanSendIconC::BuildPartFile(FILE *fp, MsgC *msg){//// Build the content-type header for this body part//   StringC	headStr;   headStr += "Content-Type: message/rfc822\n\n";   if ( !headStr.WriteFile(fp) ) {      StringC	errmsg("Could not write file: \"");      errmsg += data->msgFile;      errmsg += "\".\n";      errmsg += SystemErrorMessage(errno);      sendWin->PopupMessage(errmsg);      return False;   }//// Make a copy of the message//   if ( !msg->WriteFile(fp, /*copyHead=*/True, /*allHead=*/True,      			/*statHead=*/False, /*addBlank=*/False,			/*protectFroms=*/False) )      return False;//// Extract the subject//   HeaderC	*sub = msg->Header("Subject");   if ( sub ) data->SetSubject(sub->full);   return True;} // End BuildPartFile/*--------------------------------------------------------------- *  Method to build a MIME message body for the specified MIME tree */BooleanSendIconC::BuildPartFile(FILE *fp, MsgPartC *tree){   return tree->WriteFile(data->msgFile, fp);}/*--------------------------------------------------------------- *  Method to determine the number of body bytes for a message part */voidSendIconC::CalcBodySize(FILE *fp){   if ( fp ) {      fseek(fp, 0, SEEK_END);      data->bytes = (int)ftell(fp);   }   else {      struct stat	stats;      if ( stat(data->msgFile, &stats) == 0 )	 data->bytes = (int)stats.st_size;   }   data->bodyBytes = data->bytes - data->headBytes - 1/*blank line*/;   if ( data->extBytes > 0 ) data->bodyBytes -= (data->extBytes + 1);}/*--------------------------------------------------------------- *  Method to update the variables using the values in an include window */voidSendIconC::Update(IncludeWinC *iw){//// Delete the existing data and start over//   delete data;   data = NULL;//// Build a message part and open the message file//   FILE	*fp = CreatePart();   if ( !fp ) return;//// Initialize data from include window//   Boolean	error = !BuildPartFile(fp, iw);   if ( !error ) {      fseek(fp, 0, SEEK_SET);      error = !data->ScanHead(fp);   }   if ( !error ) CalcBodySize(fp);   fclose(fp);   if ( !error ) InitIcon();} // End Update/*--------------------------------------------------------------- *  Method to change the message file */BooleanSendIconC::SetSourceFile(char *file, Boolean del){   data->Reset();   data->msgFile    = file;   data->delMsgFile = del;   if ( !data->ScanHead() ) return False;   CalcBodySize();   InitIcon();   return True;} // End SetSourceFile/*--------------------------------------------------------------- *  Method to initialize the icon labels */voidSendIconC::InitIcon(){   dropColor = get_color("SendIconC", data->conStr, "validDropColor",   			  rt->TextArea(), "green");   popupLabel.Clear();//// Create the popup menu label//   StringC	desc;   data->GetDescription(desc);   if ( desc.size() ) {      popupLabel = "Desc: ";      if ( desc[0] != '\"' ) popupLabel += "\"" + desc + "\"";      else		     popupLabel += desc;      popupLabel += "\n";   }   popupLabel += "Type: " + data->conStr;   if ( data->IsExternal() ) popupLabel += " (external-body)";   popupLabel += "\n";   StringC	accStr;   if ( data->IsExternal() ) {      switch ( data->accType ) {	 case (AT_LOCAL_FILE):	accStr = "local-file";	break;	 case (AT_ANON_FTP):	accStr = "anon-ftp";	break;	 case (AT_FTP):		accStr = "ftp";		break;	 case (AT_TFTP):	accStr = "tftp";		break;	 case (AT_MAIL_SERVER):	accStr = "mail-server";	break;	 case (AT_INLINE):	 default:	    break;      }      if ( accStr.size() > 0 ) {	 popupLabel += "access-type: ";	 popupLabel += accStr;	 popupLabel += "\n";      }   }   if ( data->dataFile.size() > 0 ) {      popupLabel += "name: ";      popupLabel += data->dataFile;      popupLabel += "\n";   }//// Add access parameters//   if ( data->IsExternal() ) {      ParamC	*param = data->accParams;      while ( param ) {	 if ( popupLabel.size() > 0 ) popupLabel += '\n';	 popupLabel += param->full;	 param = param->next;      }   }//// Remove last newline//   if ( popupLabel.EndsWith('\n') ) popupLabel.CutEnd(1);//// Create the icon label.//   StringC	label;   if ( data->subject ) data->subject->GetValueText(label);   if ( label.size() == 0 ) {      if      ( desc.size()           ) label = desc;      else if ( data->dataFile.size() ) label = data->dataFile;      else				label = data->conStr;   }//// Add external info//   if ( data->IsExternal() ) {      accStr.Clear();      switch ( data->accType ) {	 case (AT_LOCAL_FILE):	accStr = "local";	break;	 case (AT_ANON_FTP):	accStr = "anon-ftp";	break;	 case (AT_FTP):		accStr = "ftp";		break;	 case (AT_TFTP):	accStr = "tftp";	break;	 case (AT_MAIL_SERVER):	accStr = "mail-server";	break;	 case (AT_INLINE):				break;      }      if ( accStr.size() > 0 ) {	 label += " (";	 label += accStr;	 label += " access)";      }   }   SetLabel(label);} // End InitIcon/*--------------------------------------------------------------- *  desctructor */SendIconC::~SendIconC(){   delete data;}/*--------------------------------------------------------------- *  Method to return a plain text description of this graphic */BooleanSendIconC::GetText(StringC& text){//// Substitute address for %a//   Boolean	error = False;   if ( sendWin->DescTemplate().size() > 0 ) {      StringC	addrStr;      addrStr += (int)this;      StringC	label = sendWin->DescTemplate();      label.Replace("%a", addrStr);      text += label;   }   else      error = !GetPartText(data, text);   return !error;} // End GetText/*--------------------------------------------------------------- *  Method to return a plain text description of a message part */BooleanSendIconC::GetPartText(MsgPartC *part, StringC& text){   Boolean	error = False;//// If this is a multipart, scan and process children//   if ( part->IsMultipart() ) {      part->Scan(NULL, part->bodyBytes, NULL);      MsgPartC	*child = part->child;      while ( child && !error ) {	 error = !GetPartText(child, text);	 child = child->next;      }   }//// If this is a mail attachment or an inline message, text part or uuencoded//    file, return that.//   else if ( part->IsMail() || (!part->IsExternal() &&	     (part->IsText() || part->Is822() || part->IsUUencoded())) ) {      error = !part->GetText(text);   }//// If there is no suitable text representation, insert a message//   else {      text += "\n\n(";      if ( part->IsExternal() ) text += "Attached ";      else			text += "Included ";      switch ( part->conType ) {	 case CT_PLAIN:		text += "Text";		break;	 case CT_RICH:		text += "RichText";	break;	 case CT_GIF:		text += "GIF Image";	break;	 case CT_JPEG:		text += "JPEG Image";	break;	 case CT_BASIC_AUDIO:	text += "U-LAW Audio";	break;	 case CT_MPEG:		text += "MPEG Video";	break;	 case CT_OCTET:		text += "Binary";	break;	 case CT_POSTSCRIPT:	text += "PostScript";	break;	 case CT_RFC822:	text += "Mail Message";	break;	 case CT_UNKNOWN:	text +=  part->conStr;	break;      } // End switch type      StringC	desc;      part->GetDescription(desc);      if ( desc.size() > 0 || part->dataFile.size() > 0 ) {	 text += " File: ";	 if ( desc.size() > 0 ) text += desc;	 else			text += part->dataFile;      }      text += ")\n";   } // End if no suitable text representation is available   return !error;} // End GetPartText/*--------------------------------------------------------------- *  Method to build a MIME message body for this file */BooleanSendIconC::Write(FILE *fp, StringListC *contList){//// Copy any Content- headers//   HeaderC	*head = data->headers;   StringC	headStr;   Boolean	error = False;   while ( head ) {      if ( head->key.StartsWith("Content-", IGNORE_CASE) ) {	 headStr = head->full;	 headStr += '\n';	 if ( contList ) error = !AddHeader(headStr, *contList);	 else		 error = !headStr.WriteFile(fp);	 if ( error ) return False;      }      head = head->next;   }   if ( !contList ) {      headStr = "\n";      if ( !headStr.WriteFile(fp) ) return False;   }//// Copy the body//   return data->CopyText("", fp, NULL, /*copyHead*/False, /*copyExtHead*/True,   			 /*copyBody*/True, /*protectFroms*/False,			 /*restoreFroms*/False, /*endWithNL*/False);} // End Write

⌨️ 快捷键说明

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