pub fn parse_subject(subject: &str) -> Option<SubjectParts>Expand description
Parse a multi-part Usenet/email subject line.
Recognises five marker formats (in priority order):
- Parenthesised fraction:
(03/17)or( 3 / 17 ) - Bracketed fraction:
[2/4](only when both sides are digits) - English “Part N/M” (case-insensitive)
- English “Part N of M” /
part3of17(case-insensitive) - Dash-separated fraction:
- 03/17
Leading Re:, Fwd:, and Fw: prefixes are stripped before matching
(repeatedly, to handle nested re-forwards). The extracted part marker is
removed from the subject to produce base_subject.
§Return value
Returns None only when:
subjectis empty, orsubjectcontains ayEncmarker (those posts use a distinct encoding that is explicitly out of scope for this crate).
Otherwise returns Some(SubjectParts). When no part-marker pattern
matches, part_index and part_total are both None and base_subject
is the prefix-stripped, trimmed input.
§Never panics
This function never panics on any input, including strings containing arbitrary Unicode code points.
§Examples
use uuencoding_multi::parse_subject;
// Parenthesised fraction — the most common Usenet format.
let sp = parse_subject("bigfile.rar (2/5)").unwrap();
assert_eq!(sp.part_index, Some(2));
assert_eq!(sp.part_total, Some(5));
assert_eq!(sp.base_subject, "bigfile.rar");use uuencoding_multi::parse_subject;
// Re: prefix is stripped before matching.
let sp = parse_subject("Re: archive.tar.gz (03/17)").unwrap();
assert_eq!(sp.part_index, Some(3));
assert_eq!(sp.part_total, Some(17));use uuencoding_multi::parse_subject;
// yEnc subject → None (out of scope for this crate).
assert!(parse_subject("\"file.nfo\" yEnc (1/3)").is_none());use uuencoding_multi::parse_subject;
// Empty input → None.
assert!(parse_subject("").is_none());use uuencoding_multi::parse_subject;
// No marker → Some with None fields and subject preserved.
let sp = parse_subject("just a plain subject").unwrap();
assert_eq!(sp.part_index, None);
assert_eq!(sp.part_total, None);
assert_eq!(sp.base_subject, "just a plain subject");