Example #1
0
/**
*  @brief
*    Gets a AngelScript function declaration
*/
String Script::GetAngelScriptFunctionDeclaration(const String &sFunctionName, const String &sFunctionSignature, bool bCppToAngelScript) const
{
	// Start with the PixelLight function signature (e.g. "void(int,float)")
	String sFunctionDeclaration = sFunctionSignature;

	// Find the index of the "("
	int nIndex = sFunctionDeclaration.IndexOf("(");
	if (nIndex > -1) {

		// [HACK] AngelScript really don't like something like "string MyFunction(string)", it want's "string @MyFunction(const string &)"!
		// I assume that "@" means "AngelScript, take over the control of the given memory". I wasn't able to find the documentation about
		// the AngelScript function declaration syntax, just "scriptstring.cpp" as example.
		if (bCppToAngelScript && sFunctionDeclaration.IndexOf("string") > -1) {
			String sParameters = sFunctionDeclaration.GetSubstring(nIndex);	// Find the parameters part in the string
			sParameters.Replace("string", "const string &");				// Change parameters
			sFunctionDeclaration.Delete(nIndex);							// Remove parameters from original function declaration
			sFunctionDeclaration.Replace("string", "string @");				// Change return
			sFunctionDeclaration += sParameters;							// Construct new function declaration
			nIndex = sFunctionDeclaration.IndexOf("(");						// Update the "(" index
		}

		// Create the AngelScript function declaration (e.g. "void MyFunction(int,float)")
		sFunctionDeclaration.Insert(' ' + sFunctionName, nIndex);
	}

	// Return the AngelScript function declaration (e.g. "void MyFunction(int,float)")
	return sFunctionDeclaration;
}
Example #2
0
void DisplayMenuToClient (edict_t *ent, MenuText *menu)
{
   if (!IsValidPlayer (ent))
      return;

   int clientIndex = ENTINDEX (ent) - 1;

   if (menu != null)
   {
      String tempText = String (menu->menuText);
      tempText.Replace ("\v", "\n");

      char *text = g_localizer->TranslateInput (tempText);
      tempText = String (text);

      // make menu looks best
      for (int i = 0; i <= 9; i++)
         tempText.Replace (FormatBuffer ("%d.", i), FormatBuffer ("\\r%d.\\w", i));

      text = tempText;

      while (strlen (text) >= 64)
      {
         MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, g_netMsg->GetId (NETMSG_SHOWMENU), null, ent);
            WRITE_SHORT (menu->validSlots);
            WRITE_CHAR (-1);
            WRITE_BYTE (1);

         for (int i = 0; i <= 63; i++)
            WRITE_CHAR (text[i]);

         MESSAGE_END ();

         text += 64;
      }

      MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, g_netMsg->GetId (NETMSG_SHOWMENU), null, ent);
         WRITE_SHORT (menu->validSlots);
         WRITE_CHAR (-1);
         WRITE_BYTE (0);
         WRITE_STRING (text);
      MESSAGE_END();

      g_clients[clientIndex].menu = menu;
   }
   else
   {
      MESSAGE_BEGIN (MSG_ONE_UNRELIABLE, g_netMsg->GetId (NETMSG_SHOWMENU), null, ent);
         WRITE_SHORT (0);
         WRITE_CHAR (0);
         WRITE_BYTE (0);
         WRITE_STRING ("");
      MESSAGE_END();

     g_clients[clientIndex].menu = null;
   }
   CLIENT_COMMAND (ent, "speak \"player/geiger1\"\n"); // Stops others from hearing menu sounds..
}
   IMAPResult
   IMAPCommandNamespace::ExecuteCommand(std::shared_ptr<HM::IMAPConnection> pConnection, std::shared_ptr<IMAPCommandArgument> pArgument)
   {
      if (!pConnection->IsAuthenticated())
         return IMAPResult(IMAPResult::ResultNo, "Authenticate first");

      std::shared_ptr<IMAPSimpleCommandParser> pParser = std::shared_ptr<IMAPSimpleCommandParser>(new IMAPSimpleCommandParser());
      pParser->Parse(pArgument);

      if (pParser->WordCount() < 1)
         return IMAPResult(IMAPResult::ResultBad, "NAMESPACE command requires exactly 0 parameter.");

      String sPublicFolderName = Configuration::Instance()->GetIMAPConfiguration()->GetIMAPPublicFolderName();
      String hierarchyDelimiter = Configuration::Instance()->GetIMAPConfiguration()->GetHierarchyDelimiter();
      hierarchyDelimiter.Replace(_T("\\"), _T("\\\\"));

      String sPersonalNamespace = "((\"\" \"" + hierarchyDelimiter + "\"))";
      String sOtherUsersNamespace = "NIL";
      String sSharedNamespaces = "((\"" + sPublicFolderName + "\" \"" + hierarchyDelimiter + "\"))";
      String sResponse;
      
      sResponse.Format(_T("* NAMESPACE %s %s %s\r\n"), sPersonalNamespace.c_str(), sOtherUsersNamespace.c_str(), sSharedNamespaces.c_str());
      sResponse += pArgument->Tag() + _T(" OK namespace command complete\r\n");

      pConnection->SendAsciiData(sResponse);   

      return IMAPResult();
   }
Example #4
0
void TagToFnTask::SpcToUndr(SongInfo& info)
{
    String strTemp;

    strTemp = info.GetTitle();
    strTemp.Replace(_T(" "), _T("_"));
    info.SetTitle(strTemp);

    strTemp = info.GetArtist();
    strTemp.Replace(_T(" "), _T("_"));
    info.SetArtist(strTemp);

    strTemp = info.GetAlbum();
    strTemp.Replace(_T(" "), _T("_"));
    info.SetAlbum(strTemp);

    strTemp = info.GetGenre();
    strTemp.Replace(_T(" "), _T("_"));
    info.SetGenre(strTemp);

    strTemp = info.GetYear();
    strTemp.Replace(_T(" "), _T("_"));
    info.SetYear(strTemp);
}
Example #5
0
void SettingsHelper::SetLocaleData(
    /* [in] */ ArrayOf<Byte>* data,
    /* [in] */ Int32 size)
{
    // Check if locale was set by the user:
    AutoPtr<IResources> res;
    mContext->GetResources((IResources**)&res);
    AutoPtr<IConfiguration> conf;
    res->GetConfiguration((IConfiguration**)&conf);
    // TODO: The following is not working as intended because the network is forcing a locale
    // change after registering. Need to find some other way to detect if the user manually
    // changed the locale
    Boolean temp;
    if (conf->IsUserSetLocale(&temp), temp) return;  // Don't change if user set it in the SetupWizard

    AutoPtr<IAssetManager> asset;
    mContext->GetAssets((IAssetManager**)&asset);
    AutoPtr<ArrayOf<String> > availableLocales;
    asset->GetLocales((ArrayOf<String>**)&availableLocales);
    // Replace "_" with "-" to deal with older backups.
    String localeCode = String((const char*)(data->GetPayload()), size);
    localeCode.Replace('_', '-');

    AutoPtr<ILocale> loc;
    for (Int32 i = 0; i < availableLocales->GetLength(); ++i) {
        if ((*availableLocales)[i].Equals(localeCode)) {
            AutoPtr<ILocaleHelper> helper;
            CLocaleHelper::AcquireSingleton((ILocaleHelper**)&helper);
            helper->ForLanguageTag(localeCode, (ILocale**)&loc);
            break;
        }
    }
    if (loc == NULL) return; // Couldn't find the saved locale in this version of the software

    //try {
    AutoPtr<IIActivityManager> defualtAM = ActivityManagerNative::GetDefault();
    AutoPtr<IConfiguration> config;
    defualtAM->GetConfiguration((IConfiguration**)&config);
    config->SetLocale(loc);
    config->SetUserSetLocale(TRUE);

    defualtAM->UpdateConfiguration(config);
    //} catch (RemoteException e) {
    //Intentionally left blank
    //}
}
Example #6
0
String SanitateAssetName(const String& name)
{
    String fixedName = name;
    fixedName.Replace("<", "");
    fixedName.Replace(">", "");
    fixedName.Replace("?", "");
    fixedName.Replace("*", "");
    fixedName.Replace(":", "");
    fixedName.Replace("\"", "");
    fixedName.Replace("/", "");
    fixedName.Replace("\\", "");
    fixedName.Replace("|", "");
    
    return fixedName;
}
Example #7
0
void JSBModule::WriteIncludes(String& source)
{

    Vector<JSBHeader*> allheaders;

    for (unsigned i = 0; i < enums_.Size(); i++)
    {
        allheaders.Push(enums_.At(i)->header_);
    }

    for (unsigned i = 0; i < classes_.Size(); i++)
    {
        allheaders.Push(classes_.At(i)->GetHeader());
    }

    Vector<JSBHeader*> included;
    for (unsigned i = 0; i < allheaders.Size(); i++)
    {
        JSBHeader* header = allheaders.At(i);

        if (included.Contains(header))
            continue;

        String headerPath = GetPath(header->filepath_);

		String headerfile = GetFileNameAndExtension(header->filepath_);

        headerPath.Replace(JSBind::ROOT_FOLDER + "/Source/Atomic/", "Atomic/");

        source.AppendWithFormat("#include <%s%s>\n", headerPath.CString(), headerfile.CString());

        included.Push(header);
    }

    for (unsigned i = 0; i < includes_.Size(); i++)
    {
        if (includes_[i].StartsWith("<"))
            source.AppendWithFormat("#include %s\n", includes_[i].CString());
        else
            source.AppendWithFormat("#include \"%s\"\n", includes_[i].CString());
    }
}
Example #8
0
void
POP3Connection::_LogClientCommand(const String &sClientData) const
//---------------------------------------------------------------------------()
// DESCRIPTION:
// Logs one client command.
//---------------------------------------------------------------------------()
{
    if (!Logger::Instance()->GetLogPOP3())
        return;

    String sLogData = sClientData;

    // Remove any password from the log.
    PasswordRemover::Remove(PasswordRemover::PRPOP3, sLogData);

    // Append
    sLogData = "RECEIVED: " + sLogData;
    sLogData.Replace(_T("\r\n"), _T("[nl]"));

    LOG_POP3(GetSessionID(), GetIPAddressString(), sLogData);
}
// Called to parse a RCSS number declaration.
bool PropertyParserNumber::ParseValue(Property& property, const String& value, const ParameterMap& ROCKET_UNUSED_PARAMETER(parameters)) const
{
	ROCKET_UNUSED(parameters);

	// Default to a simple number.
	property.unit = Property::NUMBER;

	// var to save string representation of suffix
	String stSuffix;

	// Check for a unit declaration at the end of the number.
	for (size_t i = 0; i < unit_suffixes.size(); i++)
	{
		const UnitSuffix& unit_suffix = unit_suffixes[i];

		if (value.Length() < unit_suffix.second.Length())
			continue;

		if (strcasecmp(value.CString() + (value.Length() - unit_suffix.second.Length()), unit_suffix.second.CString()) == 0)
		{
			property.unit = unit_suffix.first;
			stSuffix = unit_suffix.second;
			break;
		}
	}

	float float_value;
	if ((sscanf(value.CString(), "%f", &float_value) == 1)
		|| (!stSuffix.Empty() && sscanf(value.Replace(stSuffix, "").CString(), "%f", &float_value) == 1))
	{
		property.value = Variant(float_value);
		return true;
	}

	return false;
}
/* This function takes a file name and normalizes
 * all the directory names included in the path by
 * removing spaces and dots at the end. It also
 * shortens each directory and the file name to a
 * maximum of 248 or 96 characters.
 */
String BonkEnc::Utilities::NormalizeFileName(const String &fileName)
{
	Int	 maxLength = 248;

	/* Set smaller maximum path component length on old systems.
	 */
#ifdef __WIN32__
	OSVERSIONINFOA	 vInfo;

	vInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);

	GetVersionExA(&vInfo);

	if (vInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) maxLength = 96;
#endif

	String	 rFileName = fileName;
	String	 dir = fileName;
	String	 tmpDir;
	Int	 lastBS = 0;

	for (Int i = 0; i < dir.Length(); i++)
	{
		if (dir[i] == '\\' || dir[i] == '/')
		{
			String	 tmpDir2 = tmpDir;

			/* Shorten to at most maxLength characters.
			 */
			if (tmpDir.Length() - lastBS > maxLength)
			{
				tmpDir2 = String().CopyN(tmpDir, lastBS + maxLength);

				i -= (tmpDir.Length() - lastBS - maxLength);
			}

			/* Replace trailing dots and spaces.
			 */
			while (tmpDir2.EndsWith(".") || tmpDir2.EndsWith(" ")) { tmpDir2[tmpDir2.Length() - 1] = 0; i--; }

			if (tmpDir2 != tmpDir)
			{
				rFileName.Replace(tmpDir, tmpDir2);

				tmpDir = tmpDir2;
				dir = rFileName;
			}

			lastBS = i;
		}

		tmpDir[i] = dir[i];
	}

	/* Shorten file name to maxLength characters.
	 */
	if (rFileName.Length() - lastBS > maxLength) rFileName = String().CopyN(rFileName, lastBS + maxLength);

	/* Replace trailing spaces.
	 */
	while (rFileName.EndsWith(" ")) { rFileName[rFileName.Length() - 1] = 0; }

	return rFileName;
}
Example #11
0
   void StringParserTester::Test()
   {  
      String s = "AAAA";
      if (s.CompareNoCase(_T("aaaa")) != 0) throw;

      s = "AAAA";
      if (s.CompareNoCase(_T("bbbb")) == 0) throw;

      s = "AAAA";
      if (s.Equals(_T("aaaa"), true)) throw;

      s = "AAAA";
      if (!s.Equals(_T("aaaa"), false)) throw;

      s = "ZZZZZ";
      if (!s.Equals(_T("ZZZZZ"), false)) throw;

      s = "";
      if (!s.Equals(_T(""), false)) throw;

      // Test a few String functions
      String sTest = "TEST";
      sTest.Replace(_T("TEST"), _T("test"));
      if (sTest != _T("test")) throw;

      sTest = "test";
      sTest.Replace(_T("TEST"), _T("dummy"));
      if (sTest != _T("test")) throw;

      sTest = "test";
      sTest.ReplaceNoCase(_T("TEST"), _T("TEST"));
      if (sTest != _T("TEST")) throw;

      sTest = "TeSt";
      sTest.ReplaceNoCase(_T("TEST"), _T("TEST"));
      if (sTest != _T("TEST")) throw;

      sTest = "TestDummy";
      sTest.ReplaceNoCase(_T("testdummy"), _T("TestDummyReplaced"));
      if (sTest != _T("TestDummyReplaced")) throw;

      sTest = "TestDummy";
      sTest.ReplaceNoCase(_T("test"), _T("TestA"));
      if (sTest != _T("TestADummy")) throw;

      sTest = "Test Test Test Test";
      sTest.ReplaceNoCase(_T("Test"), _T("TEST"));
      if (sTest != _T("TEST TEST TEST TEST")) throw;
      
      sTest = "Test TestA Test Test";
      sTest.ReplaceNoCase(_T("TestA"), _T("TESTB"));
      if (sTest != _T("Test TESTB Test Test")) throw;
 
      // Check email addresses

      
      if (StringParser::IsValidEmailAddress("@")) throw;
      if (StringParser::IsValidEmailAddress("a")) throw;      
      if (StringParser::IsValidEmailAddress("test@")) throw;
      if (StringParser::IsValidEmailAddress("@.com")) throw;
      if (StringParser::IsValidEmailAddress("\"va@ff\"@test.co.uk")) throw;
      if (StringParser::IsValidEmailAddress("some one@test.co.uk")) throw;
      if (StringParser::IsValidEmailAddress("<someone@test.co.uk>")) throw;
      if (StringParser::IsValidEmailAddress("va ff@test.co.uk")) throw;
      if (!StringParser::IsValidEmailAddress("test@test.com")) throw;
      if (!StringParser::IsValidEmailAddress("test@hmailserver.com")) throw;
      if (!StringParser::IsValidEmailAddress("test_test@hmailserver.com")) throw;
      if (!StringParser::IsValidEmailAddress("bill@microsoft.com")) throw;
      if (!StringParser::IsValidEmailAddress("martin@hmailserver.com")) throw;
      if (!StringParser::IsValidEmailAddress("vaff@test.co.uk")) throw;
      if (!StringParser::IsValidEmailAddress("va'ff@test.co.uk")) throw;
      if (!StringParser::IsValidEmailAddress("\"va ff\"@test.co.uk")) throw;
      

      if (StringParser::ExtractAddress("\"va@ff\"@test.co.uk").Compare(_T("\"va@ff\"")) != 0) throw;
      if (StringParser::ExtractAddress("test@test.co.uk").Compare(_T("test")) != 0) throw;
      if (StringParser::ExtractAddress("t'est@test.co.uk").Compare(_T("t'est")) != 0) throw;
      if (StringParser::ExtractAddress("\"t@es@\"@test.co.uk").Compare(_T("\"t@es@\"")) != 0) throw;
      if (StringParser::ExtractAddress("test@test").Compare(_T("test")) != 0) throw;
      if (StringParser::ExtractAddress("t\"est@test.com").Compare(_T("t\"est")) != 0) throw;

      if (StringParser::ExtractDomain("t\"est@test.com").Compare(_T("test.com")) != 0) throw;
      if (StringParser::ExtractDomain("t'est@test.co.uk").Compare(_T("test.co.uk")) != 0) throw;
      if (StringParser::ExtractDomain("\"t@est\"@test.co.uk").Compare(_T("test.co.uk")) != 0) throw;
      if (StringParser::ExtractDomain("\"t@es@\"@test.co.uk").Compare(_T("test.co.uk")) != 0) throw;
      if (StringParser::ExtractDomain("test@test.com").Compare(_T("test.com")) != 0) throw;

      if (!StringParser::WildcardMatch("Test", "Test")) throw;
      if (!StringParser::WildcardMatch("", "")) throw;
      if (!StringParser::WildcardMatch("Test*", "Testar")) throw;
      if (!StringParser::WildcardMatch("Test*", "Test")) throw;
      if (StringParser::WildcardMatch("Test*", "Te")) throw;

	  if (!StringParser::WildcardMatch("*two*", "one-two-three")) throw;
	  if (StringParser::WildcardMatch("*two*", "one-three")) throw;
	  if (StringParser::WildcardMatch("?two?", "one-two-three")) throw;
	  if (!StringParser::WildcardMatch("?two?", "-two-")) throw;

     // Short strings.
     if (!StringParser::WildcardMatch("?", "A")) throw;
     if (StringParser::WildcardMatch("?", "AA")) throw;
     if (!StringParser::WildcardMatch("*", "A")) throw;
     if (!StringParser::WildcardMatch("*", "AA")) throw;
     if (!StringParser::WildcardMatch("*", "")) throw;
     if (StringParser::WildcardMatch("?", "")) throw;

     // Unicode strings
     if (!StringParser::WildcardMatch(_T("??語"), _T("標準語"))) throw;
     if (StringParser::WildcardMatch(_T("?語"), _T("標準語"))) throw;
     if (!StringParser::WildcardMatch(_T("?準?"), _T("標準語"))) throw;
     if (StringParser::WildcardMatch(_T("?準"), _T("標準語"))) throw;
     if (!StringParser::WildcardMatch(_T("標*"), _T("標準語"))) throw;

     // Matching email addresses
     if (!StringParser::WildcardMatch("test@*", "test@test.com")) throw;
     if (!StringParser::WildcardMatch("test@test.co.*", "test@test.co.uk")) throw;
     if (StringParser::WildcardMatch("test@test.co.*", "test@test.com")) throw;
     if (StringParser::WildcardMatch("test@test.co.*", "test@test.co")) throw;

     // Long strings.
     String k10String;
     for (int i = 0; i < 1000; i++)
        k10String  += "AAAAAAAAAA";

     String s310CharString;
     for (int i = 0; i < 31; i++)
        s310CharString  += "AAAAAAAAAA";

     if (!StringParser::WildcardMatch(_T("*"), k10String)) throw;
     if (!StringParser::WildcardMatch(s310CharString, s310CharString)) throw;

     char *p = 0;
     p = StringParser::Search("test", 4, "e");
     if (*p != 'e') throw;
     p = StringParser::Search("test", 4, "es");
     if (*p != 'e') throw;     
     p = StringParser::Search("test", 4, "n");
     if (p != 0) throw;      
     p = StringParser::Search("test", 4, "t");
     if (*p != 't') throw; 
     p = StringParser::Search("test ", 5, " ");
     if (*p != ' ') throw;  
     p = StringParser::Search("lest ", 5, "l");
     if (*p != 'l') throw; 
     p = StringParser::Search("testp", 4, "p");
     if (p != 0) throw;  
     p = StringParser::Search("testp", 5, "");
     if (*p != 't') throw;  
     p = StringParser::Search("", 0, "test");
     if (p != 0) throw;  
     p = StringParser::Search("", 0, "");
     if (p != 0) throw;  
     p = StringParser::Search("test", 4, "p");
     if (p != 0) throw;  
     p = StringParser::Search("test", 4, "feb");
     if (p != 0) throw;

      // RESULT:
      /*
         Strings containing 80% us-ascii characters:
         QP is about 50% faster.

         Strings containing 100% non-usascii
         B64 is about 10% faster.
      */

     String input = _T("A B C");
     std::vector<String> result = StringParser::SplitString(input, _T(" "));
     if (result.size() != 3)
        throw;

     input = "A B";
     result = StringParser::SplitString(input, " ");
     if (result.size() != 2)
        throw;

     // Test Contains and ContainsNoCase
     String s1 = "Test";
     String s2 = "Test";
     Assert(s1.Contains(s2));

     s1 = "Test";
     s2 = "Tes";
     Assert(s1.Contains(s2));

     s1 = "Test";
     s2 = "est";
     Assert(s1.Contains(s2));

     s1 = "Test";
     s2 = "est";
     Assert(s1.Contains(s2));

     s1 = "Te";
     s2 = "Tes";
     Assert(!s1.Contains(s2));

     s1 = "Test";
     s2 = "TEST";
     Assert(!s1.Contains(s2));

     s1 = "Test";
     s2 = "TEST";
     Assert(s1.ContainsNoCase(s2));

     s1 = "ABCDEFGHIJKLMNOPQ";
     s2 = "hijkl";
     Assert(s1.ContainsNoCase(s2));

     s1 = "ABCDEFGHIJKLMNOPQ";
     s2 = "hijkl";
     Assert(!s1.Contains(s2));

   }
   bool 
   SignatureAdder::SetSignature(std::shared_ptr<Message> message, 
      std::shared_ptr<const Domain> sender_domain, 
      std::shared_ptr<const Account> sender_account,
      std::shared_ptr<MessageData> &message_data)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Sets the signature of the message, based on the signature in the account
   // settings and domain settings.
   //---------------------------------------------------------------------------()
   {  
      if (!message)
      {
         assert(0);
         // Input error
         return false;
      }

      if (!sender_domain)
      {
         // Not a local sender - nothing to do.
         return false;
      }

      if (!sender_domain->GetAddSignaturesToLocalMail() && GetMessageIsLocal_(message))
      {
         // The message is local, but we have configured
         // the server not to add signatures to local email.
         return false;
      }

      String signature_plain_text;
      String signature_html;

      // First check if an account signature has been specified.
      if (sender_account && sender_account->GetEnableSignature())
      {
         signature_plain_text = sender_account->GetSignaturePlainText();
         signature_html = sender_account->GetSignatureHTML();

         if (!signature_plain_text.IsEmpty() && signature_html.IsEmpty())
         {
            // Plain text specified but not HTML. Copy plain text to HTML.
            signature_html = signature_plain_text;
            signature_html.Replace(_T("\r\n"), _T("<br>\r\n"));
         }
      }

      if (sender_domain->GetEnableSignature())
      {
         String sDomainPlainText = sender_domain->GetSignaturePlainText();
         String sDomainHTML = sender_domain->GetSignatureHTML();

         if (!sDomainPlainText.IsEmpty() && sDomainHTML.IsEmpty())
         {
            // Plain text specified but not HTML. Copy plain text to HTML.
            sDomainHTML = sDomainPlainText;
            sDomainHTML.Replace(_T("\r\n"), _T("<br>\r\n"));
         }

         // Check if we should overwrite the account signature with the 
         // domain signature, if we should append it, or if we just should
         // keep it.
         if (sender_domain->GetSignatureMethod() == HM::Domain::SMSetIfNotSpecifiedInAccount)
         {
            if (signature_plain_text.IsEmpty()) 
               signature_plain_text = sDomainPlainText;
            if (signature_html.IsEmpty())
               signature_html = sDomainHTML;
         }
         else if (sender_domain->GetSignatureMethod() == HM::Domain::SMAppendToAccountSignature)
         {
            signature_plain_text += "\r\n\r\n" + sDomainPlainText;
            signature_html += "<br><br>" + sDomainHTML;
         }
         else if (sender_domain->GetSignatureMethod() == HM::Domain::SMOverwriteAccountSignature)
         {
            signature_plain_text = sDomainPlainText;
            signature_html = sDomainHTML;
         }            
      }

      if (signature_plain_text.IsEmpty() && signature_html.IsEmpty())  
      {
         // No signature should be created.
         return false;
      }

      // A signature should be created.
      if (!message_data)
      {
         message_data = std::shared_ptr<MessageData>(new MessageData());
         std::shared_ptr<Account> emptyAccount;
         if (!message_data->LoadFromMessage(emptyAccount, message))
            return false;
      }

      if (!sender_domain->GetAddSignaturesToReplies() && GetMessageIsReply_(message_data))
      {
         // The message is a reply, but we have configured the
         // server not to add signatures to replies
         return false;
      }

      if (sender_account)
      {
         signature_plain_text.ReplaceNoCase(_T("%User.FirstName%"), sender_account->GetPersonFirstName());
         signature_plain_text.ReplaceNoCase(_T("%User.LastName%"), sender_account->GetPersonLastName());

         signature_html.ReplaceNoCase(_T("%User.FirstName%"), sender_account->GetPersonFirstName());
         signature_html.ReplaceNoCase(_T("%User.LastName%"), sender_account->GetPersonLastName());
      }

      auto text_plain_body_part = message_data->GetBodyTextPlainPart();
      if (text_plain_body_part)
      {
         String text_plan_body_content = text_plain_body_part->GetUnicodeText();
         text_plan_body_content += "\r\n" + signature_plain_text;
         text_plain_body_part->SetUnicodeText(text_plan_body_content);
      }

      auto text_html_body_part = message_data->GetBodyTextHtmlPart();
      if (text_html_body_part)
      {
         String text_html_body_content = text_html_body_part->GetUnicodeText();
         text_html_body_content += "<br/>\r\n" + signature_html;
         text_html_body_part->SetUnicodeText(text_html_body_content);
      }

      return true;      


   }
Example #13
0
bool Script::SetSourceCode(const String &sSourceCode)
{
	// Clear the previous script
	Clear();

	// Backup the given source code
	m_sSourceCode = sSourceCode;

	// Is there source code?
	if (m_sSourceCode.GetLength()) {
		// Is there already a AngelScript engine instance?
		if (!m_pAngelScriptEngine)
			m_pAngelScriptEngine = AngelScriptContext::AddContextReference();

		// Get a AngelScript module instance
		if (m_pAngelScriptEngine) {
			// Add the global functions
			for (uint32 i=0; i<m_lstGlobalFunctions.GetNumOfElements(); i++) {
				// Get the global function
				GlobalFunction *psGlobalFunction = m_lstGlobalFunctions[i];

				// [TODO] It looks like that AngelScript (2.20.2) has currently no support for namespaces... so right now I'am doing
				// an ugly hack: e.g. "PL.Timing.GetTimeDifference()" is written within scripts as "PL_Timing_GetTimeDifference()"
				String sFunction;
				if (psGlobalFunction->sNamespace.GetLength()) {
					sFunction = psGlobalFunction->sNamespace;
					sFunction.Replace('.', '_');
					sFunction += '_';
					sFunction += psGlobalFunction->sFunction;
				} else {
					sFunction = psGlobalFunction->sFunction;
				}

				// Get the AngelScript function declaration
				String sFunctionDeclaration = GetAngelScriptFunctionDeclaration(sFunction, psGlobalFunction->pDynFunc->GetSignature(), true);

				// Register global AngelScript function
				const int nFunctionID = m_pAngelScriptEngine->RegisterGlobalFunction(sFunctionDeclaration, asFUNCTION(AngelScriptFunctionCallback), asCALL_GENERIC);
				if (nFunctionID < 0) {
					// Error!
					String sErrorDescription;
					switch (nFunctionID) {
						case asNOT_SUPPORTED:
							sErrorDescription = " (The calling convention is not supported)";
							break;

						case asWRONG_CALLING_CONV:
							sErrorDescription = " (The function's calling convention doesn't match callConv)";
							break;

						case asINVALID_DECLARATION:
							sErrorDescription = " (The function declaration is invalid)";
							break;

						case asNAME_TAKEN:
							sErrorDescription = " (The function name is already used elsewhere)";
							break;
					}
					LogOutput(Log::Error, "Failed to register the global AngelScript function '" + sFunctionDeclaration + '\'');
				} else {
					// Put a pointer to the global function into the user data of the registered AngelScript function
					asIScriptFunction *pAngelScriptFunction = m_pAngelScriptEngine->GetFunctionDescriptorById(nFunctionID);
					if (pAngelScriptFunction)
						pAngelScriptFunction->SetUserData(psGlobalFunction);
				}
			}

			// Get the AngelScript module
			m_pAngelScriptModule = m_pAngelScriptEngine->GetModule(AngelScriptContext::GetUniqueName(), asGM_ALWAYS_CREATE);
			if (m_pAngelScriptModule) {
				// Add script section
				if (m_pAngelScriptModule->AddScriptSection(Name.Get(), sSourceCode, sSourceCode.GetLength()) >= 0) {
					// Compile the script
					const int nResult = m_pAngelScriptModule->Build();
					if (nResult >= 0) {
						// Done
						return true;
					} else {
						// Error!
						String sErrorDescription;
						switch (nResult) {
							case asINVALID_CONFIGURATION:
								sErrorDescription = " (The AngelScript engine configuration is invalid)";
								break;

							case asERROR:
								sErrorDescription = " (The script failed to build)";
								break;

							case asBUILD_IN_PROGRESS:
								sErrorDescription = " (Another thread is currently building)";
								break;

							case asINIT_GLOBAL_VARS_FAILED:
								sErrorDescription = " (It was not possible to initialize at least one of the global variables)";
								break;
						}
						LogOutput(Log::Error, "Failed to compile the script" + sErrorDescription);
					}
				} else {
					// Error!
					LogOutput(Log::Error, "Failed to add script section");
				}
			}
		}
	} else {
		// No script at all - done
		return true;
	}

	// Error!
	return false;
}