Code Monkey home page Code Monkey logo

Comments (10)

trickbooter avatar trickbooter commented on July 20, 2024

I have found that replacing the DecodeQP method with this...
public static string DecodeQuotedPrintables(string input)
{
var occurences = new Regex(@"=[0-9A-Z]{2}", RegexOptions.Multiline);
var matches = occurences.Matches(input);
foreach (Match match in matches)
{
char hexChar = (char)Convert.ToInt32(match.Groups[0].Value.Substring(1), 16);
input = input.Replace(match.Groups[0].Value, hexChar.ToString());
}
return input.Replace("=\r\n", "");
}

resolves the issue. I don't know enough about QP to know what is correct and what isn't.

from s22.imap.

jjd1241 avatar jjd1241 commented on July 20, 2024

I am having a similar issue. When saving some messages, there is no body when it gets saved. Some work, some don't. The attachments are coming. In said message, there doesn't seem to be quoted printable. The messages that work do have this.

from s22.imap.

trickbooter avatar trickbooter commented on July 20, 2024

Previous post removed, incorrect fix. indexer (i) + 2 was correct.

from s22.imap.

jjd1241 avatar jjd1241 commented on July 20, 2024

On 12/5/2012 5:34 AM, trickbooter wrote:

Previous post removed, incorrect fix. indexer (i) + 2 was correct.


Reply to this email directly or view it on GitHub
#21 (comment).

Is there something i can do on my end to fix this issue? By your
comment, I have to override QPDecode.

Thanks,

Jason

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

Thanks for reporting, I'll look into it. Can you post an example mail message (the "raw" message with mail headers and body) or forward one to me so that I can re-produce the problem?

from s22.imap.

trickbooter avatar trickbooter commented on July 20, 2024

I did read that QP encodes to a certain length (80 chars?) and that a special sequence is used to denote this, =\r\n. This needs to be dealt with. For me, this was the crux of the issue (see code below).

internal static string QPDecode(string value, Encoding encoding) {
            try {
                using (MemoryStream m = new MemoryStream()) {
                    for (int i = 0; i < value.Length; i++) {
                        if(value[i] == '=' && value[i+1] == '\r' && value[i+2]=='\n') {
                            i = i + 2;
                        } else if (value[i] == '=') {
                            string hex = value.Substring(i + 1, 2);
                            m.WriteByte(Convert.ToByte(hex, 16));
                            i = i + 2;
                        } else {
                            m.WriteByte(Convert.ToByte(value[i]));
                        }
                    }
                    return encoding.GetString(m.ToArray());
                }
            } catch {
                throw new FormatException("value is not a valid quoted-printable " +
                    "encoded string");
            }
        }

Using the existing method, the code decodes my message as (snipped to preserve confidentiality and shown as the c# raw string hence the \ escape char on the "...)
\r\n\r\n<rm xmlns=3D"http://www

after replacing the QPDecode' method with the one shown above, the same message decodes as follows...
\r\n\r\n<rm xmlns="http://www

I can forward you an email if you like, but I'd rather not post an email to this forum as it will reveal some private info. Have you got an email I can send to in confidence?

Many Thanks

Paul

from s22.imap.

AntonKedrov avatar AntonKedrov commented on July 20, 2024

Hi! That's a Soft Line Breaks. Non-significant line break.
Check out Rule #5 (Soft Line Breaks) in RFC 1521 (http://www.ietf.org/rfc/rfc1521.txt).
You should just skip \r\n (or \n) in QPDecode:

    string hex = value.Substring(i + 1, 2);
    if (hex != Environment.NewLine)
        m.WriteByte(Convert.ToByte(hex, 16));
    i = i + 2;

Or could be New Line in value string represented as \n, while Environment.NewLine is \r\n? If so, then code should be:

    string hex = value.Substring(i + 1, 2);
    if (hex=="\r\n")
    {
        i += 2;
    }
    else if (hex.StartsWith("\n"))
    {
        i += 1;
    }
    else
    {
        m.WriteByte(Convert.ToByte(hex, 16));
        i += 2;
    }

from s22.imap.

trickbooter avatar trickbooter commented on July 20, 2024

Agreed, I understand what they are. However, the standard QP Decode method
works for my incoming emails only after I made the changes I presented in
my last email.

On 13 January 2013 11:50, rocknroll-mind [email protected] wrote:

Hi! That's a Soft Line Breaks. Non-significant line break.
Check out Rule #5 (Soft Line Breaks) in RFC 1521 (
http://www.ietf.org/rfc/rfc1521.txt).
You should just skip \r\n (or \n) in QPDecode:

string hex = value.Substring(i + 1, 2);
if (hex != Environment.NewLine)
    m.WriteByte(Convert.ToByte(hex, 16));
i = i + 2;

Or could be New Line in value string represented as \n, while
Environment.NewLine is \r\n? If so, then code should be:

string hex = value.Substring(i + 1, 2);
if (hex=="\r\n")
{
    i += 2;
}
else if (hex.StartsWith("\n"))
{
    i += 1;
}
else
{
    m.WriteByte(Convert.ToByte(hex, 16));
    i += 2;
}


Reply to this email directly or view it on GitHubhttps://github.com//issues/21#issuecomment-12192661.

from s22.imap.

smiley22 avatar smiley22 commented on July 20, 2024

You are right, I just submitted a patch to address it.

from s22.imap.

trickbooter avatar trickbooter commented on July 20, 2024

Thanks. It is an excellent library. Well maintain, functionally coded.

On Saturday, 26 January 2013 at 15:31, smiley22 wrote:

You are right, I just submitted a patch to address it.


Reply to this email directly or view it on GitHub (#21 (comment)).

from s22.imap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.