Skip to content

Commit

Permalink
Added custom formatter for the Newsgroups: header.
Browse files Browse the repository at this point in the history
Fixes issue #162
  • Loading branch information
jstedfast committed May 11, 2024
1 parent 6d34651 commit a57bcaa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions gmime/gmime-header.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static struct {
{ "Content-Disposition", g_mime_header_format_content_disposition },
{ "Content-Id", g_mime_header_format_message_id },
{ "Disposition-Notification-To", g_mime_header_format_addrlist },
{ "Newsgroups", g_mime_header_format_newsgroups },
};


Expand Down Expand Up @@ -905,6 +906,50 @@ g_mime_header_format_received (GMimeHeader *header, GMimeFormatOptions *options,
}


/**
* g_mime_header_format_newsgroups:
* @header: a #GMimeHeader
* @options: (nullable): a #GMimeFormatOptions or %NULL
* @value: a Newsgroups header value
* @charset: a charset (note: unused)
*
* Parses the @value and then re-formats it to conform to the formatting options,
* folding the value if necessary.
*
* Returns: a newly allocated string containing the reformatted value.
**/
char *
g_mime_header_format_newsgroups (GMimeHeader *header, GMimeFormatOptions *options, const char *value, const char *charset)
{
/* https://www.rfc-editor.org/rfc/rfc5536#section-3.1.4
*
* The Newsgroups header field specifies the newsgroup(s) to which the
* article is posted.
*
* newsgroups = "Newsgroups:" SP newsgroup-list CRLF
*
* newsgroup-list = *WSP newsgroup-name
* *( [FWS] "," [FWS] newsgroup-name ) *WSP
*
* newsgroup-name = component *( "." component )
*
* component = 1*component-char
*
* component-char = ALPHA / DIGIT / "+" / "-" / "_"
*
* Not all servers support optional FWS in the list of newsgroups. In
* particular, folding the Newsgroups header field over several lines
* has been shown to harm propagation significantly. Optional FWS in
* the <newsgroup-list> SHOULD NOT be generated, but MUST be accepted.
*
* Based on this, it seems better to avoid reformatting the value at all.
*/
const char *newline = g_mime_format_options_get_newline (options);

return g_strdup_printf (" %s%s", value, newline);
}


/**
* g_mime_header_format_default:
* @header: a #GMimeHeader
Expand Down
1 change: 1 addition & 0 deletions gmime/gmime-header.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ char *g_mime_header_format_message_id (GMimeHeader *header, GMimeFormatOptions *
char *g_mime_header_format_references (GMimeHeader *header, GMimeFormatOptions *options, const char *value, const char *charset);
char *g_mime_header_format_addrlist (GMimeHeader *header, GMimeFormatOptions *options, const char *value, const char *charset);
char *g_mime_header_format_received (GMimeHeader *header, GMimeFormatOptions *options, const char *value, const char *charset);
char *g_mime_header_format_newsgroups (GMimeHeader *header, GMimeFormatOptions *options, const char *value, const char *charset);
char *g_mime_header_format_default (GMimeHeader *header, GMimeFormatOptions *options, const char *value, const char *charset);


Expand Down

0 comments on commit a57bcaa

Please sign in to comment.