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

📄 imapserverc.c

📁 linux下的E_MAIL客户端源码
💻 C
📖 第 1 页 / 共 5 页
字号:
ImapServerC::SetFlags(int msgnum, u_int state){   if ( dataPending ) {      // A command has been issued which has left data in transit currently!!      // XXX - It seems rude, but maybe the solution is to open a second socket      // to the IMAP server to set the flag(s)?      cerr << "Avoiding logic flaw at " << __FILE__ << ":" <<	      __LINE__ << " - status of message " << msgnum <<	      " will not be changed\n";      return False;   }   StringC	cmd = "STORE ";   cmd += msgnum;   cmd += " FLAGS (";   Boolean	needSpace = False;   if ( state & MSG_READ ) {      if ( needSpace ) cmd += ' ';      cmd += "\\Seen";      needSpace = True;   }   if ( state & MSG_DELETED ) {      if ( needSpace ) cmd += ' ';      cmd += "\\Deleted";      needSpace = True;   }   if ( state & MSG_REPLIED ) {      if ( needSpace ) cmd += ' ';      cmd += "\\Answered";      needSpace = True;   }   if ( state & MSG_FLAGGED ) {      if ( needSpace ) cmd += ' ';      cmd += "\\Flagged";      needSpace = True;   }#if 0   if ( state & MSG_NEW ) {      if ( needSpace ) cmd += ' ';      cmd += "\\Recent";      needSpace = True;   }   if ( state & MSG_SAVED ) {      if ( needSpace ) cmd += ' ';      cmd += "Saved";      needSpace = True;   }   if ( state & MSG_FORWARDED ) {      if ( needSpace ) cmd += ' ';      cmd += "Forwarded";      needSpace = True;   }   if ( state & MSG_RESENT ) {      if ( needSpace ) cmd += ' ';      cmd += "Resent";      needSpace = True;   }   if ( state & MSG_PRINTED ) {      if ( needSpace ) cmd += ' ';      cmd += "Printed";      needSpace = True;   }   if ( state & MSG_FILTERED ) {      if ( needSpace ) cmd += ' ';      cmd += "Filtered";      needSpace = True;   }#endif   // Send a "STORE <msgnum> -FLAGS (\Seen)" if the flags are empty   if (cmd.EndsWith("FLAGS (")) {      cmd = "STORE ";      cmd += msgnum;	  cmd += " -FLAGS (\\Seen";   }   cmd += ')';   StringListC	output;   return RunCommand(cmd, output);} // End SetFlags/*------------------------------------------------------------------------ * Function to send COPY command and wait for response. */BooleanImapServerC::Copy(int msgnum, CharC mailbox, StringListC& output){   StringC	cmd = "COPY ";   cmd += msgnum;   cmd += ' ';   cmd += mailbox;   return RunCommand(cmd, output);}/*------------------------------------------------------------------------ * Function to send APPEND command and wait for response. */BooleanImapServerC::Append(CharC mailbox, CharC data, StringListC& output){   StringC	tag;   GenTag(tag);   StringC	cmd = tag;   cmd += "APPEND ";   cmd += mailbox;   cmd += " {";   cmd += (int)data.Length();   cmd += "}";   if ( !PutLine(cmd) ) return False;   if ( !GetLine(cmd) ) return False;   while ( !cmd.StartsWith('+') && !cmd.StartsWith(tag) ) {      output.add(cmd);      if ( !GetLine(cmd) ) return False;   }//// See if server is ready for data//   if ( !cmd.StartsWith('+') ) {      cmd.CutBeg(tag.size());      output.add(cmd);      return False;   }//// Send data//   if ( !PutLine(data) ) return False;//// Wait for tagged response//   if ( !GetLine(cmd) ) return False;   while ( !cmd.StartsWith(tag) ) {      output.add(cmd);      if ( !GetLine(cmd) ) return False;   }   cmd.CutBeg(tag.size());   output.add(cmd);   // Parse output and make sure it worked!   u_int       count = output.size();   int i;   for (i=0; i<count; i++) {      CharC    resp = *output[i];      if ( resp.StartsWith("NO ") || resp.StartsWith("BAD ") ) return False;   }   return True;} // End Append/*------------------------------------------------------------------------ * Function to send APPEND command and wait for response. */BooleanImapServerC::Append(CharC mailbox, StringListC& headList, char *bodyFile,		    StringListC& output){//// Open body file//   FILE	*fp = fopen(bodyFile, "r");   if ( !fp ) {      StringC	errmsg("Could not open file \"");      errmsg += bodyFile;      errmsg += "\"\n";      errmsg += SystemErrorMessage(errno);      halApp->PopupMessage(errmsg);      return False;   }//// Get size of data//   int		size = 0;   u_int	count = headList.size();   StringC	*headStr;   int	i;   for (i=0; i<count; i++) {      headStr = headList[i];      size += headStr->size() + 1;  // Add one for the CR that will be added   }   size += 2;	// Blank line (including CR that will be added)   fseek(fp, 0, SEEK_END);   size += (int)ftell(fp);   fseek(fp, 0, SEEK_SET);//// Build command//   StringC	tag;   GenTag(tag);   StringC	cmd = tag;   cmd += "APPEND ";   cmd += mailbox;   cmd += " {";   cmd += size;   cmd += "}";   Boolean	error = !PutLine(cmd);   if ( !error ) error = !GetLine(cmd);   while ( !error && !cmd.StartsWith('+') && !cmd.StartsWith(tag) ) {      output.add(cmd);      error = !GetLine(cmd);   }//// See if server is ready for data//   if ( !error && !cmd.StartsWith('+') ) {      cmd.CutBeg(tag.size());      output.add(cmd);      error = True;   }//// Send headers//   count = headList.size();   for (i=0; !error && i<count; i++) {      headStr = headList[i];      error = !PutLine(*headStr, /*terminate=*/True);   }//// Send blank line//   if ( !error ) error = !PutLine("\n", /*terminate=*/True);//// Send body//#define BUFLEN	1024   char	buffer[BUFLEN];   buffer[0] = 0;   if ( !error ) count = fread(buffer, 1, BUFLEN-1, fp);   while ( !error && count > 0 ) {      buffer[count] = 0;      error = !PutLine(buffer, /*terminate=*/False);      if ( !error ) count = fread(buffer, 1, BUFLEN-1, fp);   }   fclose(fp);//// Send termination//   if ( !error ) error = !PutLine("\n");//// Wait for tagged response//   if ( !error ) error = !GetLine(cmd);   while ( !error && !cmd.StartsWith(tag) ) {      output.add(cmd);      error = !GetLine(cmd);   }   cmd.CutBeg(tag.size());   output.add(cmd);   // Parse output and make sure it worked!   count = output.size();   for (i=0; i<count; i++) {      CharC    resp = *output[i];      if ( resp.StartsWith("NO ") || resp.StartsWith("BAD ") ) return False;   }   return !error;} // End Append/*------------------------------------------------------------------------ * Function to send FIND MAILBOXES command and wait for response. */BooleanImapServerC::ListMailboxes(CharC pattern, StringListC& mailboxes,					  StringListC& output){   StringC	cmd = "FIND ALL.MAILBOXES ";   cmd += pattern;   Boolean	success = RunCommand(cmd, output);   if ( !success ) return False;//// Loop through output and get names//   u_int	count = output.size();   StringC	tmp;   int	i;   for (i=0; i<count; i++) {      CharC	name = *output[i];      if ( name.StartsWith("* MAILBOX ", IGNORE_CASE) ) {	 name.CutBeg(10); 	 name.Trim();	 tmp = name;	 mailboxes.add(tmp);      }   }//// Remove names from output//   count = output.size();   for (i=count-1; i>=0; i--) {      CharC	name = *output[i];      if ( name.StartsWith("* MAILBOX ", IGNORE_CASE) )	 output.remove(i);   }   return True;} // End ListMailboxes/*------------------------------------------------------------------------ * Function to see if a mailbox exists */BooleanImapServerC::Exists(CharC name){   StringC	cmd = "FIND ALL.MAILBOXES ";   cmd += name;   StringListC	output;   Boolean	success = RunCommand(cmd, output);   if ( !success ) return False;//// Loop through output and check for name//   u_int	count = output.size();   int	i;   for (i=0; i<count; i++) {      CharC	line = *output[i];      if ( line.StartsWith("* MAILBOX ", IGNORE_CASE) ) {	 line.CutBeg(10); 	 line.Trim();	 if ( line.Equals(name, IGNORE_CASE) ) return True;      }   }   return False;} // End Exists/*--------------------------------------------------------------- *  Method to ask user if they want to retry the login */BooleanImapServerC::RetryLogin(char *msgStr){   static QueryAnswerT	answer;//// Create the dialog if necessary//   static Widget	dialog = NULL;   if ( !dialog ) {      halApp->BusyCursor(True);      WArgList	args;      args.DialogStyle(XmDIALOG_FULL_APPLICATION_MODAL);      if ( halApp->questionPM ) args.SymbolPixmap(halApp->questionPM);      dialog = XmCreateQuestionDialog(*halApp, "retryLoginWin", ARGS);      XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)AnswerQuery,		    (XtPointer)&answer);      XtAddCallback(dialog, XmNcancelCallback,		    (XtCallbackProc)AnswerQuery, (XtPointer)&answer);//// Trap window manager close function//      XmAddWMProtocolCallback(XtParent(dialog), halApp->delWinAtom,			      (XtCallbackProc)WmClose,			      (caddr_t)&answer);      halApp->BusyCursor(False);   } // End if query dialog not created//// Display the message//   WXmString    wstr = msgStr;   XtVaSetValues(dialog, XmNmessageString, (XmString)wstr, NULL);//// Show the dialog//   XtManageChild(dialog);   XMapRaised(halApp->display, XtWindow(XtParent(dialog)));//// Simulate the main event loop and wait for the answer//   answer = QUERY_NONE;   while ( answer == QUERY_NONE ) {      XtAppProcessEvent(halApp->context, XtIMXEvent);      XSync(halApp->display, False);   }   XtUnmanageChild(dialog);   XSync(halApp->display, False);   XmUpdateDisplay(dialog);   return (answer == QUERY_YES);} // End RetryLogin/*--------------------------------------------------------------- *  Method to perform wildcard expansions on the names in a list. *  Any new names are added to the list. */voidImapServerC::ExpandList(StringListC& list, StringListC& output){//// Loop through strings//   u_int	count = list.size();   for (int i=0; i<count; i++) {      StringC	*name = list[i];//// If there are any wildcards in the name, ask the server to expand them//      if ( name->Contains('*') ||	   name->Contains('%') ||	   name->Contains('?') ) {	 StringListC	nameList;	 if ( ListMailboxes(*name, nameList, output) && nameList.size() > 0 ) {//// Add these names to the end of the list and remove the original pattern.//	    list.remove(i);	    list += nameList;	    count = list.size();	    i--; // Since pattern was removed	 }      } // End if the name is a pattern   } // End for each name} // End ExpandList/*------------------------------------------------------------------------ * Function to send SEARCH command and wait for response. */BooleanImapServerC::Search(CharC pattern, IntListC& numbers, StringListC& output){   StringC	cmd = "SEARCH ";   cmd += pattern;   Boolean	success = RunCommand(cmd, output);   if ( !success ) return False;//// Loop through output and get numbers//   u_int	count = output.size();   StringC	tmp;   char		numStr[16];   int		num;   int	i;   for (i=0; i<count; i++) {      CharC	line = *output[i];      if ( line.StartsWith("* SEARCH ", IGNORE_CASE) ) {	 line.CutBeg(9); 	 line.Trim();//// Loop through numbers and add to list//	 u_int		offset = 0;	 CharC		word = line.NextWord(offset);	 while ( word.Length() > 0 ) {	    strncpy(numStr, word.Addr(), word.Length());	    numStr[word.Length()] = 0;	    num = atoi(numStr);	    numbers.add(num);	    offset = word.Addr() - line.Addr() + word.Length();	    word   = line.NextWord(offset);	 }      } // End if line is search result   } // End for each output line//// Remove numbers from output//   count = output.size();   for (i=count-1; i>=0; i--) {      CharC	line = *output[i];      if ( line.StartsWith("* SEARCH ", IGNORE_CASE) )	 output.remove(i);   }   return True;} // End Search

⌨️ 快捷键说明

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