Skip to content

Commit

Permalink
Small refactoring of the MIME header formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
karastojko committed Jul 28, 2020
1 parent 58e91fa commit 3f6c5c5
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 107 deletions.
22 changes: 21 additions & 1 deletion include/mailio/codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ class MAILIO_EXPORT codec
**/
static const char SPACE_CHAR = ' ';

/**
Space character as string.
**/
static const std::string SPACE_STR;

/**
Double space string.
**/
static const std::string DOUBLE_SPACE_STR;

/**
Exclamation mark character.
**/
Expand Down Expand Up @@ -114,6 +124,11 @@ class MAILIO_EXPORT codec
*/
static const char SEMICOLON_CHAR = ';';

/**
Semicolon character as string.
*/
static const std::string SEMICOLON_STR;

/**
Zero number character.
**/
Expand All @@ -139,6 +154,11 @@ class MAILIO_EXPORT codec
**/
static const char QUOTE_CHAR = '"';

/**
Quote character as string.
**/
static const std::string QUOTE_CHAR_STR;

/**
Left parenthesis character.
**/
Expand Down Expand Up @@ -252,7 +272,7 @@ class MAILIO_EXPORT codec
Decoder line length policy.
**/
line_len_policy_t _decoder_line_policy;

/**
Strict mode for encoding/decoding.
**/
Expand Down
49 changes: 35 additions & 14 deletions include/mailio/mime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dtext = \%d33-\%d90 / \%d94-\%d126 ; printable ascii not including brackets and
address = [phrase] angle-addr / addr-spec
addr-spec = (dot-atom / quoted-string) "@" (dot-atom / dtext)
```
*/
*/

/**
Mime part implementation.
Expand All @@ -57,7 +57,7 @@ class MAILIO_EXPORT mime

/**
Top level media types.
@todo Mixed subtype is missing.
**/
enum class media_type_t {NONE, TEXT, IMAGE, AUDIO, VIDEO, APPLICATION, MULTIPART, MESSAGE};
Expand Down Expand Up @@ -116,14 +116,14 @@ class MAILIO_EXPORT mime

/**
Content transfer encodings.
@todo What is a differrence between ASCII and 7bit?
**/
enum class content_transfer_encoding_t {NONE, BIT_7, BIT_8, BASE_64, QUOTED_PRINTABLE, BINARY};

/**
Content disposition.
@todo Content disposition should be struct to keep this enum and filename?
**/
enum class content_disposition_t {NONE, INLINE, ATTACHMENT};
Expand Down Expand Up @@ -468,7 +468,7 @@ class MAILIO_EXPORT mime
Alphanumerics plus some special character allowed in the quoted text.
**/
static const std::string QTEXT;

/**
Header name allowed characters.
**/
Expand All @@ -478,7 +478,7 @@ class MAILIO_EXPORT mime
Content type attribute value allowed characters.
**/
static const std::string CONTENT_ATTR_ALPHABET;

/**
Content header value allowed characters.
*/
Expand All @@ -500,6 +500,27 @@ class MAILIO_EXPORT mime
**/
std::string format_content(bool dot_escape) const;

/**
Formatting content type to a string.
@return Content type as string.
**/
std::string format_content_type() const;

/**
Formatting transfer encoding to a string.
@return Transfer encoding as string.
**/
std::string format_transfer_encoding() const;

/**
Formatting content disposition to a string.
@return Content disposition as string.
**/
std::string format_content_disposition() const;

/**
Formats mime name.
Expand All @@ -512,7 +533,7 @@ class MAILIO_EXPORT mime

/**
Parsing header by going through header lines and calling `parse_header_line()`.
@throw * `parse_header_line(const string&)`.
**/
void parse_header();
Expand All @@ -534,10 +555,10 @@ class MAILIO_EXPORT mime
`parse_content_disposition(const string&, content_disposition_t& disposition, map<string, string>&)`.
**/
virtual void parse_header_line(const std::string& header_line);

/**
Parsing a header for the name and value.
@param header_line Header to parse.
@param header_name Header name parsed.
@param header_value Header value parsed.
Expand All @@ -561,15 +582,15 @@ class MAILIO_EXPORT mime

/**
Parsing the content transfer encoding value and attributes.
@param transfer_encoding_hdr Content transfer encoding header without name
@param encoding Content transfer encoding value parsed.
@param attributes Content transfer encoding attributes parsed in the the key/value format.
@throw mime_error Parsing content transfer encoding failure.
@throw * `parse_header_value_attributes(const string&, string&, map<string, string>&)`.
**/
void parse_content_transfer_encoding(const std::string& transfer_encoding_hdr, content_transfer_encoding_t& encoding, attributes_t& attributes) const;

/**
Parsing the content disposition value and attributes.
Expand All @@ -580,10 +601,10 @@ class MAILIO_EXPORT mime
@throw * `parse_header_value_attributes(const string&, string&, map<string, string>&)`.
**/
void parse_content_disposition(const std::string& content_disp_hdr, content_disposition_t& disposition, attributes_t& attributes) const;

/**
Parsing value and attributes of the so called content headers.
@param header Header (without name) to be parsed.
@param value Header value parsed.
@param attributes Header attributes parsed in the the key/value format.
Expand Down Expand Up @@ -665,7 +686,7 @@ class MAILIO_EXPORT mime

/**
Name of mime.
@todo Should it contain filename of the attachment?
**/
std::string _name;
Expand Down
8 changes: 8 additions & 0 deletions src/codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const string codec::HEX_DIGITS = "0123456789ABCDEF";

const string codec::CRLF = "\r\n";

const string codec::SPACE_STR(1, codec::SPACE_CHAR);

const string codec::DOUBLE_SPACE_STR(2, codec::SPACE_CHAR);

const string codec::QUOTE_CHAR_STR(1, codec::QUOTE_CHAR);

const string codec::SEMICOLON_STR(1, codec::SEMICOLON_CHAR);


int codec::hex_digit_to_int(char digit)
{
Expand Down

0 comments on commit 3f6c5c5

Please sign in to comment.