Example #1
0
   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));
}
Example #4
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";
}
Example #5
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 #6
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 #7
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 #8
0
bool CppBuilder::Cp(const String& cmd, const String& package, bool& error) {
	if(cmd.GetLength() > 2 && ToLower(cmd.Mid(0, 3)) == "cp ") {
		Vector<String> path = Split(cmd.Mid(3), ' ');
		if(path.GetCount() == 2) {
			String p = GetFileFolder(PackagePath(package));
			String p1 = NormalizePath(path[0], p);
			String p2 = NormalizePath(path[1], p);
			RealizePath(p2);
			if(!FileExists(p1)) {
				PutConsole("FAILED: " + cmd);
				error = true;
			}
			SaveFile(p2, LoadFile(p1));
		}
		return true;
	}
	return false;
}
Example #9
0
 String
 StringParser::ExtractAddress(const String &sEMailAddress)
 //---------------------------------------------------------------------------()
 // DESCRIPTION:
 // Extracts the adress from an email address string. (the part before @)
 //---------------------------------------------------------------------------()
 {
    int iAtSign = sEMailAddress.ReverseFind(_T("@"));
    String sDomain = sEMailAddress.Mid(0, iAtSign);
    return sDomain;
 }
Example #10
0
 String
 StringParser::ExtractDomain(const String &sEMailAddress)
 //---------------------------------------------------------------------------()
 // DESCRIPTION:
 // Extracts the domain from an email address string. (the part after @)
 //---------------------------------------------------------------------------()
 {
    int iAtSign = sEMailAddress.ReverseFind(_T("@"));
    String sDomain = sEMailAddress.Mid(iAtSign+1);
    return sDomain;
 }
Example #11
0
bool HelpWin::GoTo0(const String& link, bool find) {
	int q = link.Find('#');
	if(q >= 0) {
		topic = link.Mid(0, q);
		label = link.Mid(q + 1);
	}
	else {
		topic = link;
		label = Null;
	}
	Topic t = AcquireTopic(topic);
	if(!IsNull(t.text)) {
		Title(t.title.ToWString());
		view = t.text;
		view.GotoLabel(label, true);
		tree.FindSetCursor(topic);
		return true;
	}
	return false;
}
Example #12
0
   String
   FileUtilities::GetFilePath(const String & FileName)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Returns the path to the folder in which FileName resides.
   //---------------------------------------------------------------------------()
   {
      int iLastSlash = FileName.ReverseFind(_T("\\"));
      String Path = FileName.Mid(0, iLastSlash);

      return Path;
   }
Example #13
0
String XConfig::ProcessString(TSTR &lpTemp)
{
    TSTR lpStart = lpTemp;

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

    if(!bFoundEnd)
        return String();

    ++lpTemp;

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

    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 #14
0
void TopicEditor::Hyperlink(String& link, WString& text)
{
	TopicLinkDlg d;
	d.link <<= link;
	String label;
	TopicLink tl;
	int q = link.ReverseFind('#');
	if(q >= 0) {
		label = link.Mid(q + 1);
		tl = ParseTopicLink(link.Mid(0, q));
	}
	else
		tl = ParseTopicLink(link);
	if(IsNull(tl.topic)) {
		d.package.FindSetCursor(GetFileTitle(GetFileFolder(grouppath))) &&
		d.group.FindSetCursor(GetFileTitle(grouppath)) &&
		d.topic.FindSetCursor(topic.GetCurrentName());
	}
	else {
		d.package.FindSetCursor(tl.package) &&
		d.group.FindSetCursor(tl.group) &&
		d.topic.FindSetCursor(tl.topic) &&
		d.label.FindSetCursor(label);
	}
	int c = d.Run();
	if(c == IDCANCEL)
		return;
	link = ~d.link;
	if(c == IDOK)
		return;
	if(d.topic.IsCursor()) {
		String fn = AppendFileName(d.PackageGroup(d.group.GetCurrentName()),
		                           d.topic.GetCurrentName() + ".tpp");
		text = ReadTopic(LoadFile(fn)).title.ToWString();
	}
}
Example #15
0
   String
   FileUtilities::GetFileNameFromFullPath(const String & sFullPath)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Returns the filename in the full path.
   //---------------------------------------------------------------------------()
   {
      int iLastSlash = sFullPath.ReverseFind(_T("\\"));

      if (iLastSlash == -1)
      {
         // Path is relative.
         return sFullPath;
      }

      return sFullPath.Mid(iLastSlash + 1);
   }
Example #16
0
   bool
   FileUtilities::Copy(const String &sFrom, const String &sTo, bool bCreateMissingDirectories)
   {
      int iNumberOfTries = 0;
      const int iMaxNumberOfTries = 5;

      if (bCreateMissingDirectories)
      {
         String sToPath = sTo.Mid(0, sTo.ReverseFind(_T("\\")));
         CreateDirectoryRecursive(sToPath);
      }


      const int maxRecursions = 10000;
      for (int i = 0; i < maxRecursions; i++)
      {
         // Use classic api to copy the file
         if (::CopyFile(sFrom, sTo, FALSE) != 0)
         {
            //Copy OK
            return true;
         }

         iNumberOfTries ++;

         // We failed to delete the file. 

         if (iNumberOfTries >= iMaxNumberOfTries)
         {
            // We still couldn't copy the file. Lets give up and report in windows event log and hMailServer application log
            int iLastError = ::GetLastError();

            String sErrorMessage;
            sErrorMessage.Format(_T("Could not copy the file %s to %s. Tried 5 times without success. Windows eror code: %d (%s)"), sFrom, sTo, iLastError, Dictionary::GetWindowsErrorDescription(iLastError));
            ErrorManager::Instance()->ReportError(ErrorManager::High, 5048, "File::Copy", sErrorMessage);
            return false;
         }

         // Some other process must have locked the file.
         Sleep(1000);
      }

      assert(0); // if we get here, something is really strange...
      return false;
   }
Example #17
0
// from complete lib name/path (libXXX.so.ver.minVer) gets the soname (libXXX.so.ver)
String CppBuilder::GetSoname(String libName) const
{
	
	String soname = GetFileName(libName);
	int soLen = soname.GetCount();
	int soPos = ToLower(soname).ReverseFind(".so");
	if(soPos < 0)
		soPos = soLen;
	else
		soPos += 3;
	if(soname.Mid(soPos, 1) == ".")
	{
		soPos++;
		while(soPos < soLen && IsDigit(soname[soPos]))
			soPos++;
	}
	return soname.Left(soPos);
}
Example #18
0
// POSIX lib files have names in form of libXXXXXX.so.ver.minver(.rel)
// so we can't simply get file extension
String CppBuilder::GetSrcType(String fn) const
{
	fn = ToLower(fn);
	String ext = GetFileExt(fn);
	if(!HasFlag("POSIX") || ext == ".so")
		return ext;
	int soPos = fn.ReverseFind(".so");
	if(soPos < 0)
		return ext;
	fn = fn.Mid(soPos + 3);
	const char *c = ~fn;
	while(*c)
	{
		if(*c != '.' && !IsDigit(*c))
			return ext;
		c++;
	}
	return ".so";
}
Example #19
0
   bool
   MailImporter::GetRootLevelDirectory_(const String &fullPath, String &rootLevel)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Takes an input parameter such as C:\DataDir\Account\Sub1\Sub2\Test.eml and
   // returns the root of that hierarcy, such as C:\Datadir\Account in this case.
   //---------------------------------------------------------------------------()
   {
      // The file must be located in the data directory. Make sure this is the case.
      const String dataDirectory = IniFileSettings::Instance()->GetDataDirectory();

      if (!fullPath.StartsWith(dataDirectory))
         return false;

      int currentTrimPosition = dataDirectory.GetLength() + 1;

      const String publicFolderName = IMAPConfiguration::GetPublicFolderDiskName();

      // Is the file located in the public folder?
      if (fullPath.FindNoCase(publicFolderName, currentTrimPosition) == currentTrimPosition)
      {
         // The file is located in the public folder.
         currentTrimPosition += publicFolderName.GetLength() + 1;
      }
      else
      {
         // The file is either located in the queue folder or in an account folder.
         int slashPosition = fullPath.Find(_T("\\"), currentTrimPosition);
         if (slashPosition < 0)
            return false;

         int accountSlashPosition = fullPath.Find(_T("\\"), slashPosition+1);

         if (accountSlashPosition > 0)
         {
            // The file is locate din the queue folder.
            currentTrimPosition = accountSlashPosition+1;
         }
      }

      rootLevel = fullPath.Mid(0, currentTrimPosition);
      return true;
   }
Example #20
0
Vector<String> SvnInfo(const String& package)
{
	Vector<String> info;
	String d = GetFileFolder(PackagePath(package));
	if(IsSvnDir2(d)) {
		String v = Sys("svnversion " + d);
		if(IsDigit(*v))
			info.Add("#define bmSVN_REVISION " + AsCString(TrimBoth(v)));
		v = Sys("svn info " + d);
		StringStream in(v);
		while(!in.IsEof()) {
			String l = in.GetLine();
			if(l.StartsWith("URL: ")) {
				info.Add("#define bmSVN_URL " + AsCString(TrimBoth(l.Mid(5))));
				break;
			}
		}
	}
	return info;
}
Example #21
0
   bool
   FileUtilities::CreateDirectoryRecursive(const String &sDirName)
   {
      if (FileUtilities::Exists(sDirName))
         return true;

      bool isUNCPath = IsUNCPath(sDirName);

      int iLength = sDirName.GetLength();
      for (int i = 3; i < iLength; i++)
      {
         wchar_t c = sDirName.GetAt(i);

         if (c == '\\')
         {
            String sDirectoryName = sDirName.Mid(0, i);
            
            if (isUNCPath)
            {
               // Have we specified share name?
               if (!IsValidUNCFolder(sDirectoryName))
               {
                  // No. Not much to do yet. We can't check for the
                  // existance of an UNC.
                  continue;
               }
            }
            
            if (FileUtilities::Exists(sDirectoryName))
               continue;

            if (!CreateDirectory(sDirectoryName))
               return false;
         }
      }

      if (!FileUtilities::Exists(sDirName))
         return CreateDirectory(sDirName);

      return true;
   }
Example #22
0
// Parses legacy filter ID and converts it into current scaling options
bool parse_legacy_frame_config(const String &scaling_option, String &filter_id, GameFrameSetup &frame)
{
    struct
    {
        String LegacyName;
        String CurrentName;
        int    Scaling;
    } legacy_filters[6] = { {"none", "none", -1}, {"max", "StdScale", 0}, {"StdScale", "StdScale", -1},
                           {"AAx", "Linear", -1}, {"Hq2x", "Hqx", 2}, {"Hq3x", "Hqx", 3} };

    for (int i = 0; i < 6; i++)
    {
        if (scaling_option.CompareLeftNoCase(legacy_filters[i].LegacyName) == 0)
        {
            filter_id = legacy_filters[i].CurrentName;
            frame.ScaleDef = legacy_filters[i].Scaling == 0 ? kFrame_MaxRound : kFrame_IntScale;
            frame.ScaleFactor = legacy_filters[i].Scaling >= 0 ? legacy_filters[i].Scaling :
                scaling_option.Mid(legacy_filters[i].LegacyName.GetLength()).ToInt();
            return true;
        }
    }
    return false;
}
Example #23
0
   bool 
   MailImporter::MoveToNamedSubdirectory_(const String &sourceFile, String &resultFile, String &newFullPath)
   {
      // The file must be located in the data directory. Make sure this is the case.
      const String dataDirectory = IniFileSettings::Instance()->GetDataDirectory();

      if (!sourceFile.StartsWith(dataDirectory))
         return false;

      // Create a new file name.
      resultFile = Message::GenerateFileName();

      String guidFolder = resultFile.Mid(1,2);
      
      // The file could be located in an incorrect folder, not following the name standard
      // for sub folders in hMailServer. Retrieve the correct folder name so that we can
      // move the message into the correct location.
      
      String currentCorrectDirectory; 
      if (!GetRootLevelDirectory_(sourceFile, currentCorrectDirectory))
         return false;

      String destinationDirectory = FileUtilities::Combine(currentCorrectDirectory, guidFolder);
      if (!FileUtilities::Exists(destinationDirectory))
         FileUtilities::CreateDirectoryRecursive(destinationDirectory);

      String destinationFile = FileUtilities::Combine(destinationDirectory, resultFile);

      if (FileUtilities::Move(sourceFile, destinationFile))
      {
         newFullPath = destinationFile;
         return true;
      }
      
      return false;
   }
Example #24
0
   IMAPResult
   IMAPCommandUID::ExecuteCommand(shared_ptr<IMAPConnection> pConnection, shared_ptr<IMAPCommandArgument> pArgument)
   {
      if (!pConnection->IsAuthenticated())
         return IMAPResult(IMAPResult::ResultNo, "Authenticate first");

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

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

      shared_ptr<IMAPSimpleCommandParser> pParser = shared_ptr<IMAPSimpleCommandParser>(new IMAPSimpleCommandParser());

      pParser->Parse(pArgument);
      
      if (pParser->WordCount() < 2)
         return IMAPResult(IMAPResult::ResultBad, "Command requires at least 1 parameter.");

      String sTypeOfUID = pParser->Word(1)->Value();

      if (sTypeOfUID.CompareNoCase(_T("FETCH")) == 0)
      {
         if (pParser->WordCount() < 4)
            return IMAPResult(IMAPResult::ResultBad, "Command requires at least 3 parameters.");

         command_ = shared_ptr<IMAPFetch>(new IMAPFetch());
      }
      else if (sTypeOfUID.CompareNoCase(_T("COPY")) == 0)
      {

         if (pParser->WordCount() < 4)
            return IMAPResult(IMAPResult::ResultBad, "Command requires at least 3 parameters.");

         command_ = shared_ptr<IMAPCopy>(new IMAPCopy());
      }
      else if (sTypeOfUID.CompareNoCase(_T("STORE")) == 0)
      {
         if (pParser->WordCount() < 4)
            return IMAPResult(IMAPResult::ResultBad, "Command requires at least 3 parameters.");

         command_ = shared_ptr<IMAPStore>(new IMAPStore());
      }
      else if (sTypeOfUID.CompareNoCase(_T("SEARCH")) == 0)
      {
         shared_ptr<IMAPCommandSEARCH> pCommand = shared_ptr<IMAPCommandSEARCH> (new IMAPCommandSEARCH(false));
         pCommand->SetIsUID();
         IMAPResult result = pCommand->ExecuteCommand(pConnection, pArgument);

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

         return result;
      }
      else if (sTypeOfUID.CompareNoCase(_T("SORT")) == 0)
      {
         shared_ptr<IMAPCommandSEARCH> pCommand = shared_ptr<IMAPCommandSEARCH> (new IMAPCommandSEARCH(true));
         pCommand->SetIsUID();
         IMAPResult result = pCommand->ExecuteCommand(pConnection, pArgument);
         
         if (result.GetResult() == IMAPResult::ResultOK)
            pConnection->SendAsciiData(sTag + " OK UID completed\r\n");

         return result;
      }


      if (!command_)
         return IMAPResult(IMAPResult::ResultBad, "Bad command.");

      command_->SetIsUID(true);

      // Copy the first word containing the message sequence
      long lSecWordStartPos = sCommand.Find(_T(" "), 5) + 1;
      long lSecWordEndPos = sCommand.Find(_T(" "), lSecWordStartPos);
      long lSecWordLength = lSecWordEndPos - lSecWordStartPos;
      String sMailNo = sCommand.Mid(lSecWordStartPos, lSecWordLength);
      
      // Copy the second word containing the actual command.
      String sShowPart = sCommand.Mid(lSecWordEndPos + 1);

      if (sMailNo.IsEmpty())
         return IMAPResult(IMAPResult::ResultBad, "No mail number specified");

      if (!StringParser::ValidateString(sMailNo, "01234567890,.:*"))
         return IMAPResult(IMAPResult::ResultBad, "Incorrect mail number");

      // Set the command to execute as argument
      pArgument->Command(sShowPart);

      // Execute the command. If we have gotten this far, it means that the syntax
      // of the command is correct. If we fail now, we should return NO. 
      IMAPResult result = command_->DoForMails(pConnection, sMailNo, pArgument);

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

      return result;
   }
Example #25
0
bool MIValue::expect(String const &where, char exp, int i, String const &s)
{
	if(s[i] == exp)
		return true;
	int start = i - 30;
	if(start < 0)
		start = 0;
	if(!s[i])
		SetError(Format(where + " : Expected '%c', got end of string at pos %d around '%s'", exp, i, s.Mid(start, 60)));
	else
		SetError(Format(where + " : Expected '%c', got '%c' at pos %d in '%s'", exp, s[i], i, s.Mid(start, 60)));
	return false;
}