English 中文(简体)
parsing response end with extended SMTP (ESMTP)
原标题:

To use an example response from google when sent "EHLO":

250-mx.google.com at your service, [66.501.941.15]
250-SIZE 35651584
250-8BITMIME
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250 PIPELINING

Hex:

32 35 30 2D 6D 78 2E 67 6F 6F 67 6C 65 2E 63 6F 6D 20 61 74 20 79 6F 75 72 20 73 65 72 76 69 63 65 2C 20 5B 39 32 2E 34 32 31 2E 35 36 35 2E 34 32 5D 0D 0A 32 35 30 2D 53 49 5A 45 20 33 35 36 35 31 35 38 34 0D 0A 32 35 30 2D 38 42 49 54 4D 49 4D 45 0D 0A 32 35 30 2D 41 55 54 48 20 4C 4F 47 49 4E 20 50 4C 41 49 4E 0D 0A 32 35 30 2D 45 4E 48 41 4E 43 45 44 53 54 41 54 55 53 43 4F 44 45 53 0D 0A 32 35 30 20 50 49 50 45 4C 49 4E 49 4E 47 0D 0A

Since the SMTP spec states that a line must end with a CR LF (0D 0A), we can parse on those two bytes to find lines, but how do we determine the end of the response?

Over satellite, responses can be broken into pieces with a significant delay between. This means a response could end after a CR LF and not be complete ie:

250-mx.google.com at your service, [66.501.941.15]
250-SIZE 35651584
250-8BITMIME

Any logic that looks for a trailing CR LF would then assume the response is complete. IN this case I am using CryptLib to perform the SLL tunnel, but I can create the port with my own code and pass it to the library if there is some way to get an "end of response".

问题回答

The response ends on the line where there is no hyphen between the 250 and the name.

So, if the 4th character of the line is a space, that will be the last line of the response.

From section 4.2.1 of RFC 2821:

The format for multiline replies requires that every line, except the last, begin with the reply code, followed immediately by a hyphen, "-" (also known as minus), followed by text. The last line will begin with the reply code, followed immediately by < SP >, optionally some text, and < CRLF >.

This is a multiline reply in the SMTP protocol (described in RFC 821 Appendix E)

You ll notice that the first line is formatted with

CODE-FirstLine
CODE-SecondLine

However the last line is formatted like so:

CODE LastLine

Each line is delimited by a CRLF like you explained, but you know you re on the last line of a multiline reply when the code and text are not delimited by a - (minus)





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签