Skip to content

feat: update extractAllHeaders func to only use the header section for header extraction#286

Merged
Aravinda-HWK merged 4 commits into
OpenGovMail:mainfrom
prdai-archive:feat/extract-headers-from-header-section-only-279
Jun 14, 2026
Merged

feat: update extractAllHeaders func to only use the header section for header extraction#286
Aravinda-HWK merged 4 commits into
OpenGovMail:mainfrom
prdai-archive:feat/extract-headers-from-header-section-only-279

Conversation

@prdai

@prdai prdai commented May 30, 2026

Copy link
Copy Markdown
Contributor

Description

Updated the Function extractAllHeaders within internal/delivery/parser/parser.go, to first split the rawMessage utilizing double new lines and trying to find the headers within that section instead of going through the entire email message.

Verified through make test

…r header extraction

within the implementation, we are first cloning the rawMessage that is
provided because the rawMessage and rawHeaderMessage would other wise
share the same memory address, afterwards we utilize the strings.Index
to find at which point the character occur in this scneario "\r\n\r\n"
or "\n\n", and then we update the rawHeaderMessage, we default the
entire rawMessage just in case
@CLAassistant

CLAassistant commented May 30, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the extractAllHeaders function in internal/delivery/parser/parser.go to isolate the header portion of a raw message before parsing. The review feedback points out several critical issues in this implementation, including a duplicate condition bug checking for \r\n\r\n twice, inefficient string cloning, an incorrect index check that misses index 0, and an unnecessary semicolon. A refactored suggestion is provided to address these concerns.

Comment thread internal/delivery/parser/parser.go Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Aravinda-HWK
Aravinda-HWK self-requested a review June 1, 2026 15:46
Comment thread internal/delivery/parser/parser.go Outdated
@Aravinda-HWK

Copy link
Copy Markdown
Collaborator

There's no test exercising the new code path. The existing TestExtractAllHeaders only checks that valid headers are found — it does not assert that body content is excluded, nor does it cover the truncation. I'd suggest adding a small table test asserting that a message whose body contains X-Injected: evil does not produce that header, for both \r\n\r\n and \n\n separators. It locks in the intended behavior even though it currently overlaps with the break.

@Aravinda-HWK

Copy link
Copy Markdown
Collaborator

Hi @prdai , just a gentle reminder regarding this PR. Could you please take a look at the requested changes/comments when you have some time? Let us know if you need any clarification or assistance. Thanks again for the contribution.

@prdai

prdai commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

hi, i have been a bit pre occupied with starting work and i am a bit sick these days, could you give me till wed to finish this off?

@Aravinda-HWK

Copy link
Copy Markdown
Collaborator

hi, i have been a bit pre occupied with starting work and i am a bit sick these days, could you give me till wed to finish this off?

Sure, no problem at all. I just wanted to check whether this PR is active or inactive. Take your time and get well soon.

prdai added 2 commits June 11, 2026 06:23
The header-section-only refactor truncates the raw message at the
header/body boundary, which removes the trailing blank line the parse
loop relied on to flush the last header. As a result the final header
was silently dropped. Flush the pending header after the loop instead.

Add tests covering body exclusion for both \r\n\r\n and \n\n separators,
and a regression test asserting the first-blank-line break still stops
header parsing for mixed line endings (header-injection guard).
@prdai
prdai requested a review from Aravinda-HWK June 11, 2026 15:04

@Aravinda-HWK Aravinda-HWK left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Thanks for the contribution, and we are looking forward to seeing new contributions from you.

@Aravinda-HWK
Aravinda-HWK merged commit 128221c into OpenGovMail:main Jun 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] extractAllHeaders Method Allocates Entire Email into Memory instead of Header Section Only

3 participants