IMAPResult
   IMAPCommandStore::ExecuteCommand(shared_ptr<IMAPConnection> pConnection, shared_ptr<IMAPCommandArgument> pArgument)
   {


      String sTag = pArgument->Tag();
      String sCommand = pArgument->Command();

      if (!pConnection->IsAuthenticated())
         return IMAPResult(IMAPResult::ResultNo, "Authenticate first");

      if (!pConnection->GetCurrentFolder())
         return IMAPResult(IMAPResult::ResultNo, "No folder selected.");


      shared_ptr<IMAPStore> pStore = shared_ptr<IMAPStore>(new IMAPStore());
      pStore->SetIsUID(false);

      String sResponse; 
      long lMailNoStart = 6;
      long lMailNoEnd = sCommand.Find(_T(" "), lMailNoStart);
      long lMailNoLen = lMailNoEnd - lMailNoStart;
      String sMailNo = sCommand.Mid(lMailNoStart, lMailNoLen);
      String sShowPart = sCommand.Mid(lMailNoEnd);

      pArgument->Command(sShowPart);

      IMAPResult result = pStore->DoForMails(pConnection, sMailNo, pArgument);

      if (result.GetResult() == IMAPResult::ResultOK)
         pConnection->SendAsciiData(pArgument->Tag() + " OK STORE completed\r\n");

      return result;
   }
Example #2
0
template<> void Jsonize(JsonIO& io, Date& var)
{
	if(io.IsLoading()) {
		const Value& v = io.Get();
		if(IsNull(v)) {
			var = Null;
			return;
		}
		if(IsString(v)) {
			String text = v;
			if(text.GetCount() > 6) {
				Date d;
				d.year = ScanInt(text.Left(4));
				d.month = ScanInt(text.Mid(4, 2));
				d.day = ScanInt(text.Mid(6));
				if(d.IsValid()) {
					var = d;
					return;
				}
			}
		}
		throw JsonizeError("string expected for Date value");
	}
	else
		if(IsNull(var))
			io.Set(Null);
		else
			io.Set(Format("%04d%02d%02d", var.year, var.month, var.day));
}
Example #3
0
template<> void Jsonize(JsonIO& io, Time& var)
{
	if(io.IsLoading()) {
		const Value& v = io.Get();
		if(IsNull(v)) {
			var = Null;
			return;
		}
		if(IsString(v)) {
			String text = v;
			if(text.GetCount() > 15) {
				Time tm;
				tm.year = ScanInt(text.Left(4));
				tm.month = ScanInt(text.Mid(4, 2));
				tm.day = ScanInt(text.Mid(6, 2));
				tm.hour = ScanInt(text.Mid(9, 2));
				tm.minute = ScanInt(text.Mid(12, 2));
				tm.second = ScanInt(text.Mid(15));
				if(tm.IsValid()) {
					var = tm;
					return;
				}
			}
		}
		throw JsonizeError("string expected for Time value");
	}
	else
		if(IsNull(var))
			io.Set(Null);
		else
			io.Set(Format("%04d%02d%02d`T%02d:%02d:%02d",
				          var.year, var.month, var.day, var.hour, var.minute, var.second));
}
	void
	PasswordRemover::Remove(PRType prt, String &sClientCommand)
	{
      if (prt == PRIMAP)
      {
		   // Starts the second word.
         int iCommandStart = sClientCommand.Find(_T(" "));
         if (iCommandStart == -1)
            return;
      
         iCommandStart++;

         if (sClientCommand.Mid(iCommandStart, 5).CompareNoCase(_T("LOGIN")) != 0)
            return;
         
         // Find end of login name.
         int iUsernameEnd = sClientCommand.Find(_T(" "), iCommandStart + 6);
         if (iUsernameEnd <= 0)
            return;

         sClientCommand = sClientCommand.Mid(0, iUsernameEnd);
         sClientCommand += " ***";
      }
      else if (PRIMAP)
      {
         // Remove from POP3 ...
         if (sClientCommand.Mid(0, 4).CompareNoCase(_T("PASS")) != 0)
            return;

         // Remove the password.
         sClientCommand = sClientCommand.Mid(0, 4) + " ***";
      }

	}
   std::vector<String>
   IMAPFetchParser::_ParseString(String &sString)
   {

      std::vector<String> vecResult;

      _CleanFetchString(sString);

      while (!sString.IsEmpty())
      {
         long lFirstLeftBracket = sString.Find(_T("["));
         long lFirstSpace = sString.Find(_T(" "));

         if (lFirstLeftBracket >= 0 && lFirstLeftBracket < lFirstSpace)
         {
            // Find end bracket.
            long lFirstRightBracket = sString.Find(_T("]"), lFirstLeftBracket);

            // Check if we got a <> directly after the []
            if (sString.SafeGetAt(lFirstRightBracket + 1) == '<')
               lFirstRightBracket = sString.Find(_T(">"), lFirstRightBracket);

            // Parse out string between brackets.
            if (lFirstRightBracket <= 0)
            {
               sString = sString.Mid(lFirstRightBracket + 1);
               continue;
            }

            // String between brackets.
            String sResString = sString.Mid(0, lFirstRightBracket+1 );
            vecResult.push_back(sResString);

            // Cut away this from the start string.
            sString = sString.Mid(lFirstRightBracket + 1);
         }
         else if (lFirstSpace >= 0)
         {
            // Copy string from here to end.
            String sResString = sString.Mid(0, lFirstSpace );

            vecResult.push_back(sResString);

            sString = sString.Mid(lFirstSpace + 1);

         }
         else
         {
            vecResult.push_back(sString);
            sString.Empty();
         }
         

         _CleanFetchString(sString);


      }

      return vecResult;
   }
Example #6
0
String VisGenDlg::GetName()
{
	String n = layout.name;
	int l = n.GetCount() - 6;
	if(l > 0 && n.Mid(l) == "Layout")
		n = n.Mid(0, l);
	return n + "Dlg";
}
   bool
   SQLScriptRunner::ExecuteScript(shared_ptr<DALConnection> connectionObject, const String &sFile, String &sErrorMessage)
   {
      SQLScriptParser oParser(connectionObject->GetSettings(), sFile);
      if (!oParser.Parse(sErrorMessage))
      {
         sErrorMessage = "Parsing of SQL script failed: " + sFile + "\r\nError:" + sErrorMessage;
         return false;
      }

      if (oParser.GetNoOfCommands() == 0)
      {
         sErrorMessage = "Found no SQL commands in file : " + sFile;
         return false;
      }

      // 30 minute timeout per statement. Should hopefully never be needed.
      connectionObject->SetTimeout(60 * 30);

      for (int i = 0; i < oParser.GetNoOfCommands(); i++)
      {
         String sCommand = oParser.GetCommand(i);

         if (sCommand.StartsWith(_T("@@@")))
         {
            // Remove leading @@@.
            sCommand = sCommand.Mid(3);

            // Remove trailing @@@
            sCommand = sCommand.Mid(0, sCommand.Find(_T("@@@")));

            MacroParser parser(sCommand);
            Macro macro = parser.Parse();

            if (macro.GetType() == Macro::Unknown)
            {
               sErrorMessage = "Parsing of SQL script failed. Unknown macro. " + sFile + "\r\nMacro:" + sCommand;
               return false;
            }

            shared_ptr<IMacroExpander> macroExpander = connectionObject->CreateMacroExpander();
            if (!macroExpander->ProcessMacro(connectionObject, macro, sErrorMessage))
               return false;
         }
         else
         {
            if (connectionObject->TryExecute(SQLCommand(sCommand), sErrorMessage, 0, 0) != DALConnection::DALSuccess)
            {
               return false;
            }
         }
      }

      connectionObject->SetTimeout(30);

      return true;
   }
Example #8
0
   bool
   Logger::_WriteData(const String &sData, LogType lt)
   {
      CriticalSectionScope scope(m_oCritSec);

      File *file = _GetCurrentLogFile(lt);

      bool writeUnicode = false;
      bool keepFileOpen = (m_iLogMask & LSKeepFilesOpen) && (lt == Normal || lt == SMTP || lt == POP3 || lt == IMAP);

      switch (lt)
      {
      case Normal:
      case Error:
      case AWStats:
      case IMAP:
      case POP3:
      case SMTP:
         writeUnicode = false;
         break;
      case Backup:
      case Events:
         writeUnicode = true;
         break;
      }

      if (writeUnicode)
      {
         file->Write(sData);
      }
      else
      {
         AnsiString sAnsiString;
         // Let's truncate some of those crazy long log lines
         // only when debug is not enabled or loglevel <= 2
         // Only do it if long enough default is 500 by set by MaxLogLineLen
         
         int iDataLenTmp = sData.GetLength();
         m_iLogLevel = IniFileSettings::Instance()->GetLogLevel();
         m_iMaxLogLineLen = IniFileSettings::Instance()->GetMaxLogLineLen();

         if ((Logger::Instance()->GetLogDebug()) || (m_iLogLevel > 2) || (iDataLenTmp < m_iMaxLogLineLen ))
            sAnsiString = sData;
         else
            sAnsiString = sData.Mid(0, m_iMaxLogLineLen - 30) + " ... " + sData.Mid(iDataLenTmp - 25);
            // We keep 25 of end which includes crlf but need to account for middle ... too

         file->Write(sAnsiString);
      }

      if (!keepFileOpen)
         file->Close();

      return true;
   }
Example #9
0
   Macro 
   MacroParser::Parse()
   {
      if (_macroString.StartsWith(_T("HM_DROP_COLUMN_OBJECTS")))
      {
         int pos = _macroString.Find(_T(" "));

         String columnSpecifier = _macroString.Mid(pos);

         int separator = columnSpecifier.Find(_T("."));

         String tableName = columnSpecifier.Mid(0, separator);
         String columnName = columnSpecifier.Mid(separator+1);

         tableName.Trim();
         columnName.Trim();

         Macro macro;
         macro.SetType(Macro::DropColumnKeys);
         macro.SetTableName(tableName);
         macro.SetColumnName(columnName);

         return macro;
      }
      else if (_macroString == _T("UPDATE_MESSAGES_SET_FOLDER_INBOX"))
      {
         Macro macro;
         macro.SetType(Macro::SQLCEUPDATE_MESSAGES_SET_FOLDER_INBOX);
         return macro;
      }
      else if (_macroString == _T("UPDATE_FOLDERS_SET_CURRENT_UID"))
      {
         Macro macro;
         macro.SetType(Macro::SQLCEUPDATE_FOLDERS_SET_CURRENT_UID);
         return macro;
      }
      else if (_macroString == _T("UPDATE_FOLDERS_SET_NEW_PARENTFOLDERID_WHERE_ZERO"))
      {
         Macro macro;
         macro.SetType(Macro::SQLCEUPDATE_FOLDERS_SET_NEW_PARENTFOLDERID_WHERE_ZERO);
         
         return macro;
      }
      else if (_macroString == _T("SQLCE_UPDATE_IMAP_HIERARCHY_DELIMITER"))
      {
         Macro macro;
         macro.SetType(Macro::SQLCE_UPDATE_IMAP_HIERARCHY_DELIMITER);

         return macro;
      }
      
      Macro unknownMacro;
      return unknownMacro;
   }
Example #10
0
bool CppBuilder::Cd(const String& cmd) {
	if(cmd.GetLength() > 2 && ToLower(cmd.Mid(0, 3)) == "cd ") {
		String path = cmd.Mid(3);
	#ifdef PLATFOTM_POSIX
		chdir(path);
	#endif
	#ifdef PLATFORM_WIN32
		SetCurrentDirectory(path);
	#endif
		return true;
	}
	return false;
}
Example #11
0
   std::pair<int, String> 
   Language::_GetString(const String &sLine)
   {
      int iValueStart = 7;
      int iEqualsPos = sLine.Find(_T("="));
      int iValueLen = iEqualsPos - iValueStart;

      String sValue = sLine.Mid(iValueStart, iValueLen);
      String sText = sLine.Mid(iEqualsPos+1);

      int iValue = _ttoi(sValue);

      return std::make_pair(iValue, sText);
   }
Example #12
0
   void
   IMAPFetchParser::_CleanFetchString(String &sString)
   {
      if (sString.Left(1) == _T(" "))
         sString = sString.Mid(1);
      
      if (sString.Left(1) == _T("("))
         sString = sString.Mid(1);

      if (sString.Right(1) == _T(")"))
         sString = sString.Mid(0, sString.GetLength() - 1);
      

   }
Example #13
0
   std::vector<String>
   StringParser::SplitString(const String &sInput, const String &sSeperators)
   {
      // Previously, this code used boost::tokenizer to split
      // the contents of string, but I did some tests and it
      // showed that the below code was 50% faster. Not so 
      // unexpected since tokenizer is much more advanced.

      std::vector<String> vecResult;
      int iBeginning = 0;
      int iEnd = sInput.Find(sSeperators);

      if (iEnd == -1)
      {
         // The separator was not found in the string. 
         // We should put the entire string in the result.
         if (!sInput.IsEmpty())
            vecResult.push_back(sInput);

      }

      int iSeperatorLen = sSeperators.GetLength();

      while (iEnd >= 0)
      {
         int iSubStrLength = iEnd - iBeginning;
         
         String sSubString;
         sSubString = sInput.Mid(iBeginning, iSubStrLength);
         
         vecResult.push_back(sSubString);

         // Skip to the position where the next substring
         // can start
         iBeginning = iEnd + iSeperatorLen;
         iEnd = sInput.Find(sSeperators, iBeginning);   
      }

      if (iBeginning > 0)
      {
         String sSubString = sInput.Mid(iBeginning);
         if (!sSubString.IsEmpty())
            vecResult.push_back(sSubString);
      }

      return vecResult;
    
  
   }
Example #14
0
   String 
   FileUtilities::Combine(const String &path1, const String &path2)
   {
      String firstHalf = path1;
      String secondHalf = path2;

      if (firstHalf.EndsWith(_T("\\")) || firstHalf.EndsWith(_T("/")))
         firstHalf = firstHalf.Mid(0, firstHalf.GetLength() -1);

      if (secondHalf.StartsWith(_T("\\")) || secondHalf.StartsWith(_T("/")))
         secondHalf = secondHalf.Mid(1);

      String result = firstHalf + "\\" + secondHalf;

      return result;
   }
Example #15
0
String ChangeTopicLanguage(const String &topic, int lang) {
	int pos = topic.ReverseFind('$');
	if (pos < 0)
		return "";			
	String langtxt = ToLower(LNGAsText(lang));		
	return topic.Left(pos+1) + langtxt + topic.Mid(pos+1+langtxt.GetCount()); 
}
Example #16
0
void Player::ListAppendFolders(bool append)
{
    if(foldersel.ExecuteSelectDir(t_("Select music folder")))
    {
        foldersel.Close();
        if(append)
            list.DoAppendNoEdit();
        else
            list.DoInsertBeforeNoEdit();
        String plname = foldersel.Get();
        int i = plname.GetLength();
        while(--i >= 0)
        {
            if(plname[i] == '/' || plname[i] == '\\')
                break;
        }
        list(1) = plname.Mid(i + 1);
        ListInsertRow();
        list.RefreshNewRow();
        SQL.Begin();
        WaitCursor wc;
        for(int i = 0; i < foldersel.GetCount(); i++)
            AddFiles(true, foldersel.GetFile(i));
        SQL.Commit();
    }
}
Example #17
0
bool GatherTpp::MakeHtml(const char *folder, Gate2<int, int> progress) {
	DeleteFolderDeep(folder);
	DirectoryCreate(folder);

	for(int i = 0; i < tt.GetCount(); i++) {
		String topic = tt.GetKey(i);
		links.Add(topic, topic == indexTopic ? "index.html" :
		                 memcmp(topic, "topic://", 8) ? topic : TopicFileNameHtml(topic));
	}
	for(int i = 0; i < reflink.GetCount(); i++) {
		String l = reflink.GetKey(i);
		String lbl = Filter(l, CharFilterLbl);
		String f = links.Get(reflink[i], Null) + '#' + lbl;
		links.Add(l, f);
		static const char *x[] = { "::struct", "::class", "::union" };
		for(int ii = 0; ii < 3; ii++) {
			String e = x[ii];
			if(EndsWith(l, e)) {
				links.Add(l.Mid(0, l.GetLength() - e.GetLength()), f);
			}
		}
		labels.Add(l, lbl);
	}

	for(int i = 0; i < tt.GetCount(); i++) {
		if (progress(i+1, tt.GetCount()))
			return false;
		ExportPage(i, folder);
	}
	return true;
}
Example #18
0
   IPAddress
   Utilities::GetIPAddressFromReceivedHeader(const String &sReceivedHeader)
   {
      /*
      sFirstPart now contains the following
      received =  "Received"    ":"            ; one per relay
      ["from" domain]           ; sending host
      ["by"   domain]           ; receiving host
      ["via"  atom]             ; physical path
      *("with" atom)             ; link/mail protocol
      ["id"   msg-id]           ; receiver msg id
      ["for"  addr-spec]        ; initial form
      ";"    date-time         ; time received

      http://cr.yp.to/immhf/envelope.html
      In theory, the value of a Received field is tokenizable.
      In practice, SMTP servers put all sorts of badly formatted information into Received lines. 
      Hence: We only do a quick search
      */

      int iFromPos = sReceivedHeader.Find(_T("from "));
      if (iFromPos == -1)
      {
         // Could not locate IP address.
         return IPAddress();
      }

      int iBracketPos = sReceivedHeader.Find(_T("["), iFromPos );
      if (iBracketPos == -1)
      {
         // Could not locate IP address.
         return IPAddress();
      }

      int iByPos = sReceivedHeader.Find(_T("by "));
      if (iByPos >= 0 && iByPos < iBracketPos)
      {
         // Found from but no bracket.
         return IPAddress();
      }

      int iBracketEndPos = sReceivedHeader.Find(_T("]"), iBracketPos);

      int iIPLength = iBracketEndPos - iBracketPos - 1;

      String sIPAddress = sReceivedHeader.Mid(iBracketPos + 1, iIPLength);

      if (!StringParser::IsValidIPAddress(sIPAddress))
      {
         // Could not locate IP address
         assert(0);
         return IPAddress();
      }

      IPAddress address;
      address.TryParse(sIPAddress);

      return address;

   }
   String 
   MessageUtilities::GetSendersIP(boost::shared_ptr<Message> pMessage)
   {
      const String fileName = PersistentMessage::GetFileName(pMessage);

      AnsiString sHeader = PersistentMessage::LoadHeader(fileName);

      MimeHeader oHeader;
      oHeader.Load(sHeader, sHeader.GetLength(), true);

      // Locate the first Received header
      MimeField *pReceivedHeader = oHeader.GetField("Received");
      if (pReceivedHeader == 0)
         return "127.0.0.1";

      // Now we should try to find the IP in the received header.
      String sReceivedValue = pReceivedHeader->GetValue();

      int iAddressStart = sReceivedValue.Find(_T("[")) +1;
      int iAddressEnd = sReceivedValue.Find(_T("]"), iAddressStart);
      int iAddressLen = iAddressEnd - iAddressStart;

      if (iAddressLen <= 0)
         return "127.0.0.1";

      String sIPAddress = sReceivedValue.Mid(iAddressStart, iAddressLen);

      if (!StringParser::IsValidIPAddress(sIPAddress))
         return "127.0.0.1";

      return sIPAddress;
   }
Example #20
0
   DateTime
   Utilities::GetDateTimeFromReceivedHeader(const String &sReceivedHeader)
   {
      DateTime dtRetValue;

      int iLastSemicolon = sReceivedHeader.ReverseFind(_T(";"));
      if (iLastSemicolon == -1)
         return dtRetValue;

      String sDatePart = sReceivedHeader.Mid(iLastSemicolon + 1);

      /*
      sFirstPart now contains the following
      received =  "Received"    ":"            ; one per relay
      ["from" domain]           ; sending host
      ["by"   domain]           ; receiving host
      ["via"  atom]             ; physical path
      *("with" atom)             ; link/mail protocol
      ["id"   msg-id]           ; receiver msg id
      ["for"  addr-spec]        ; initial form
      ";"    date-time         ; time received

      http://cr.yp.to/immhf/envelope.html
      In theory, the value of a Received field is tokenizable.
      In practice, SMTP servers put all sorts of badly formatted information into Received lines. 
      Hence: We only do a quick search
      */

      sDatePart.Trim();

      dtRetValue = Time::GetDateTimeFromMimeHeader(sDatePart);
      
      return dtRetValue;
   }
Example #21
0
String XConfig::ProcessString(TSTR &lpTemp)
{
    TSTR lpStart = lpTemp;

    BOOL bFoundEnd = FALSE;
    BOOL bPreviousWasEscaped = FALSE;
    while(*++lpTemp)
    {
        if (*lpTemp == '\\' && lpTemp[-1] == '\\')
        {
            bPreviousWasEscaped = TRUE;
            continue;
        }
        if(*lpTemp == '"' && (bPreviousWasEscaped || lpTemp[-1] != '\\'))
        {
            bFoundEnd = TRUE;
            break;
        }
        bPreviousWasEscaped = FALSE;
    }

    if(!bFoundEnd)
        return String();

    ++lpTemp;

    TCHAR backupChar = *lpTemp;
    *lpTemp = 0;
    String string = lpStart;
    *lpTemp = backupChar;

    if (string.Length() == 2)
        return String();

    String stringOut = string.Mid(1, string.Length()-1);
    if (stringOut.IsEmpty())
        return String();

    TSTR lpStringOut = stringOut;
    while(*lpStringOut != 0 && (lpStringOut = schr(lpStringOut, '\\')) != 0)
    {
        switch(lpStringOut[1])
        {
            case 0:     *lpStringOut = 0; break;
            case '"':   *lpStringOut = '"';  scpy(lpStringOut+1, lpStringOut+2); break;
            case 't':   *lpStringOut = '\t'; scpy(lpStringOut+1, lpStringOut+2); break;
            case 'r':   *lpStringOut = '\r'; scpy(lpStringOut+1, lpStringOut+2); break;
            case 'n':   *lpStringOut = '\n'; scpy(lpStringOut+1, lpStringOut+2); break;
            case '/':   *lpStringOut = '/';  scpy(lpStringOut+1, lpStringOut+2); break;
            case '\\':  scpy(lpStringOut+1, lpStringOut+2); break;
        }

        lpStringOut++;
    }

    stringOut.SetLength(slen(stringOut));

    return stringOut;
}
Example #22
0
int StringSearch(const String &string, const String& key) {
	for(int i=0; i<(string.GetLength()-key.GetLength()); i++) {
		if(string.Mid(i, key.GetLength()) == key) {
			return i;
		}
	}
	return -1;
}
Example #23
0
int get_scaling_from_filter_name(const String &filter_id)
{
    int scaling = 1;
    if (filter_id.CompareLeftNoCase("StdScale") == 0)
    {
        scaling = filter_id.Mid(8).ToInt();
    }
    else if (filter_id.CompareLeftNoCase("Hq") == 0)
    {
        scaling = filter_id.Mid(2).ToInt();
    }
    else if (filter_id.CompareLeftNoCase("AAx") == 0)
    {
        scaling = filter_id.Mid(3).ToInt();
    }
    return scaling;
}
Example #24
0
String RemoveQuote(const String &str) {

	if(str.Left(1) == "\"" && str.Right(1) == "\"") {
		if(str.GetCount() == 2) return String("");
		return str.Mid(1, str.GetLength()-2);	
	}
	return str;
}
 bool
 POP3ClientConnection::CommandIsSuccessfull_(const String &sData)
 {
    if (sData.Mid(0,3).CompareNoCase(_T("+OK")) == 0)
       return true;
    else
       return false;
 }
Example #26
0
static String GetHostFromAddress( const String& address )
{
	int posAt = address.Find('@') ;
	if (posAt == -1)
		return address ;

	return address.Mid(posAt+1) ;
}
   void 
   POP3ClientConnection::ParseUIDLResponse_(const String &sData)
   {
      if (CommandIsSuccessfull_(sData))
      {
         // We have connected successfully.
         // Time to send the username.
         
         std::vector<String> vecLines = StringParser::SplitString(sData, "\r\n");
         std::vector<String>::iterator iter = vecLines.begin();

         if (vecLines.size() < 3)
         {
            StartMailboxCleanup_();
            return;
         }

         // Move to first line containing a message ID.
         iter++;

         while (iter != vecLines.end())
         {
            String sLine = (*iter);

            if (sLine == _T("."))
               break;

            int iSpacePos = sLine.Find(_T(" "));
            String sMessageIndex = sLine.Mid(0,iSpacePos);
            String sMessageUID = sLine.Mid(iSpacePos + 1);

            int iMessageIdx = _ttoi(sMessageIndex);
            uidlresponse_[iMessageIdx] = sMessageUID;

            iter++;
         }

         cur_message_ = uidlresponse_.begin();

         RequestNextMessage_();

         return;
      }

      QuitNow_();
   }
Example #28
0
void MainConfigDlg::FlagDlg()
{
	WithConfLayout<TopWindow> cfg;
	CtrlLayoutOKCancel(cfg, "Configuration flags");
	cfg.Sizeable().MaximizeBox();
	Vector<String> flg = SplitFlags0(String(fe));
	Vector<String> accepts = wspc.GetAllAccepts(0);
	Sort(accepts, GetLanguageInfo());
	enum { CC_SET, CC_NAME, CC_PACKAGES, CC_COUNT };
	cfg.accepts.AddColumn("Set").Ctrls(sSetOption).HeaderTab().Fixed(40);
	cfg.accepts.AddColumn("Flag", 1);
	cfg.accepts.AddColumn("Packages", 2);
	cfg.accepts.SetCount(accepts.GetCount());
	for(int i = 0; i < accepts.GetCount(); i++) {
		String acc = accepts[i];
		Vector<String> pkg;
		for(int p = 0; p < wspc.GetCount(); p++)
			if(FindIndex(wspc.package[p].accepts, acc) >= 0)
				pkg.Add(wspc[p]);
		Sort(pkg, GetLanguageInfo());
		cfg.accepts.Set(i, CC_NAME, accepts[i]);
		cfg.accepts.Set(i, CC_PACKAGES, Join(pkg, ","));
	}

	cfg.other.SetFilter(FlagFilterM);
	cfg.dll <<= cfg.gui <<= cfg.mt <<= cfg.sse2 <<= 0;
	String other;
	for(int i = 0; i < flg.GetCount(); i++) {
		String f = flg[i];
		if(!SetSw(f, cfg.dll, "DLL")
		   && !SetSw(f, cfg.gui, "GUI")
		   && !SetSw(f, cfg.mt, "MT")
		   && !SetSw(f, cfg.sse2, "SSE2")) {
			int x = (*f == '.' ? cfg.accepts.Find(f.Mid(1), CC_NAME) : -1);
			if(x >= 0)
				cfg.accepts.Set(x, CC_SET, true);
			else {
				if(!other.IsEmpty())
					other << ' ';
				other << f;
			}
		}
	}
	cfg.other <<= other;
	if(cfg.Run() == IDOK) {
		String flags;
		flags
			<< GetSw(cfg.dll, "DLL")
		    << GetSw(cfg.gui, "GUI")
		    << GetSw(cfg.mt, "MT")
			<< GetSw(cfg.sse2, "SSE2");
		for(int i = 0; i < cfg.accepts.GetCount(); i++)
			if(cfg.accepts.Get(i, CC_SET))
				flags << '.' << cfg.accepts.Get(i, CC_NAME) << ' ';
		flags << cfg.other.GetText().ToString();
		fe = Join(SplitFlags0(flags), " ").ToWString();
	}
}
Example #29
0
   String 
   Utilities::GetRecipientFromReceivedHeader(const String &sReceivedHeader)
   {
      int iLastSemicolon = sReceivedHeader.ReverseFind(_T(";"));
      if (iLastSemicolon == -1)
         return "";

      String sFirstPart = sReceivedHeader.Mid(0, iLastSemicolon);

      /*
      sFirstPart now contains the following
      received =  "Received"    ":"            ; one per relay
            ["from" domain]           ; sending host
            ["by"   domain]           ; receiving host
            ["via"  atom]             ; physical path
            *("with" atom)             ; link/mail protocol
            ["id"   msg-id]           ; receiver msg id
            ["for"  addr-spec]        ; initial form
            ";"    date-time         ; time received

      http://cr.yp.to/immhf/envelope.html
      In theory, the value of a Received field is tokenizable.
      In practice, SMTP servers put all sorts of badly formatted information into Received lines. 
      Hence: We only do a quick search
      */

      int iForPos = sFirstPart.ReverseFind(_T("for "));
      
      if (iForPos == -1)
         return "";
      
      String sAddressPart = sFirstPart.Mid(iForPos + 4);

      sAddressPart.TrimLeft(_T(" \r\n\t"));
      sAddressPart.TrimRight(_T(" \r\n\t"));

      sAddressPart.Replace(_T("<"), _T(""));
      sAddressPart.Replace(_T(">"), _T(""));
      sAddressPart.Replace(_T(" "), _T(""));

      if (!StringParser::IsValidEmailAddress(sAddressPart))
         return "";

      return sAddressPart;
   }
Example #30
0
void Put(String s, const char *splits)
{
	Vector<String> split = Split(splits, ';');
	bool was = false;
	for(int i = 0; i < split.GetCount(); i++) {
		int q = s.Find(split[i]);
		if(q >= 0) {
			if(was)
				qtf << "&\n";
			qtf << DeQtf(s.Mid(0, q));
			s = s.Mid(q);
			was = true;
		}
	}
	if(was)
		qtf << "&\n";
	qtf << DeQtf(s);
}