Esempio n. 1
0
// ---------------------------------------
bool MTRecord::FormatShortMailDescription(std::string & str_output)
{
    OTString strDescription;

    if (IsMail())
    {
        if (!HasContents())
            strDescription.Set("(empty message)");
        else
        {
            std::string str_contents = GetContents();

            if (str_contents.compare(0,8,"Subject:") == 0)
            {
                // Make the replacement.
                str_contents.replace(0, 8, "");
            }
            // -----------------------------------
            bool bTruncated = false;

            if (str_contents.size() > 30)
            {
                str_contents.erase(30, std::string::npos);
                bTruncated = true;
            }
            // -----------------------------------
            strDescription.Format("\"%s%s\"", OTString::trim(str_contents).c_str(),
                                  bTruncated ? "..." : "");
        }
    }
    // -----------------------------
    str_output = strDescription.Get();
    // -----------------------------
    return (!str_output.empty());
}
Esempio n. 2
0
// ---------------------------------------
bool MTRecord::FormatShortMailDescription(std::string & str_output)
{
    OTString strDescription;

    if (IsMail())
    {
        if (!HasContents())
            strDescription.Set("(empty message)");
        else
        {
            std::string str_temp_contents = GetContents();
            std::string str_contents      = OTString::trim(str_temp_contents);

            if (str_contents.compare(0,8,"Subject:") == 0)
            {
                // Make the replacement.
                str_contents.replace(0, 8, "");
            }
            // -----------------------------------
            bool bTruncated = false;

            if (str_contents.size() > 30)
            {
                str_contents.erase(30, std::string::npos);
                bTruncated = true;
            }
            // -----------------------------------
            // Replace any newlines with spaces...
            //
            std::replace( str_contents.begin(), str_contents.end(), '\r', ' ');
            std::replace( str_contents.begin(), str_contents.end(), '\n', ' ');

//          str_contents.erase(std::remove(str_contents.begin(), str_contents.end(), '\n'), str_contents.end());
//          str_contents.erase(std::remove(str_contents.begin(), str_contents.end(), '\r'), str_contents.end());
            // -----------------------------------
            strDescription.Format("%s%s", OTString::trim(str_contents).c_str(),
                                  bTruncated ? "..." : "");
        }
    }
    // -----------------------------
    str_output = strDescription.Get();
    // -----------------------------
    return (!str_output.empty());
}
Esempio n. 3
0
// ---------------------------------------
bool MTRecord::FormatMailSubject(std::string & str_output)
{
    str_output.clear();
    // ------------------------
    if (IsMail())
    {
        if (!HasContents())
            str_output = "(empty subject)";
        else
        {
            std::string str_temp_contents = GetContents();

            if (str_temp_contents.compare(0,8,"Subject:") == 0)
            {
                // Make the replacement.
                str_temp_contents.replace(0, 8, "");
            }
            // -----------------------------------
            // Trim it, since there is probably a space after "Subject:"
            // (Plus we want it trimmed anyway.)
            std::string str_contents = OTString::trim(str_temp_contents);
            // -----------------------------------
            // Cut the string at the first newline.
            //
            std::string::size_type pos_start = 0;
            std::string::size_type pos       = str_contents.find("\r\n", pos_start);

            if (std::string::npos == pos) // Didn't find anything.
                pos = str_contents.find ("\n", pos_start);
            // -----------------------------------
            if (std::string::npos != pos) // We found a newline.
                str_contents.erase(pos, std::string::npos);
            // -----------------------------------
            // Trim it again, just for good measure.
            str_output = OTString::trim(str_contents);
        }
    }
    // -----------------------------
    return (!str_output.empty());
}