-
Notifications
You must be signed in to change notification settings - Fork 2
FEAT: Add EML/MIME support to converter task #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d0cde43
feat: Add EML file converter using enmime library to extract email bo…
Mayureshpawar29 33ac22e
Merge branch 'main' into eml-parser
Mayureshpawar29 ca401d3
fix: refine EML attachment filename length handling.
Mayureshpawar29 6a1a7a1
feat: document EML format support for the converter task, including o…
Mayureshpawar29 ef3f6b8
refactor: Simplify filename truncation logic to ensure total length d…
Mayureshpawar29 6136184
feat: Extract and save EML headers to `headers.json` and rename the `…
Mayureshpawar29 4273ea9
refactor: centralize EML converter output processing into a dedicated…
Mayureshpawar29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package converter | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "fmt" | ||
| "mime" | ||
| "path/filepath" | ||
|
|
||
| "github.com/jhillyerd/enmime" | ||
| ) | ||
|
|
||
| type eml struct{} | ||
|
|
||
| func (c *eml) convert(data []byte, _ string) ([]converterOutput, error) { | ||
|
|
||
| envelope, err := enmime.ReadEnvelope(bytes.NewReader(data)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to parse EML: %v", err) | ||
| } | ||
|
|
||
| var outputs []converterOutput | ||
|
|
||
| addOutput := func(content []byte, fileName string, contentType string) { | ||
| if len(content) == 0 { | ||
| return | ||
| } | ||
|
|
||
| fileName = filepath.Base(fileName) | ||
|
|
||
| // Fallback for filename length | ||
| if len(fileName) > 200 { | ||
Mayureshpawar29 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ext := filepath.Ext(fileName) | ||
| base := fileName[:len(fileName)-len(ext)] | ||
| base = base[:200-len(ext)] | ||
| fileName = base + ext | ||
| } | ||
|
|
||
| // Fallback for missing content type | ||
| if contentType == "" { | ||
| opts := mime.TypeByExtension(filepath.Ext(fileName)) | ||
| if opts != "" { | ||
| contentType = opts | ||
| } else { | ||
| contentType = "application/octet-stream" | ||
| } | ||
| } | ||
|
|
||
| outputs = append(outputs, converterOutput{ | ||
| Data: content, | ||
| Metadata: map[string]string{ | ||
| "filename": fileName, | ||
Mayureshpawar29 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "content_type": contentType, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| if envelope.HTML != "" { | ||
| addOutput([]byte(envelope.HTML), "body.html", "text/html") | ||
| } | ||
| if envelope.Text != "" { | ||
| addOutput([]byte(envelope.Text), "body.txt", "text/plain") | ||
| } | ||
|
|
||
| for _, attachment := range envelope.Attachments { | ||
| addOutput(attachment.Content, attachment.FileName, attachment.ContentType) | ||
| } | ||
|
|
||
| for _, inline := range envelope.Inlines { | ||
| addOutput(inline.Content, inline.FileName, inline.ContentType) | ||
| } | ||
|
|
||
| return outputs, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| tasks: | ||
| - name: read_eml_file | ||
| type: file | ||
| path: test/pipelines/test_mail | ||
| - name: convert_from_eml | ||
| type: converter | ||
| format: eml | ||
| - name: save_output | ||
| type: file | ||
| path: output/{{ context "filename" }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| From: sender@example.com | ||
| To: receiver@example.com | ||
| Subject: Test Email with PDF, CSV, and HTML Attachments | ||
| Date: Mon, 16 Feb 2026 10:00:00 +0000 | ||
| Message-ID: <test123@example.com> | ||
| MIME-Version: 1.0 | ||
| Content-Type: multipart/mixed; boundary="BOUNDARY123" | ||
|
|
||
| --BOUNDARY123 | ||
| Content-Type: text/plain; charset="UTF-8" | ||
| Content-Transfer-Encoding: 7bit | ||
|
|
||
| Hello, | ||
|
|
||
| Please find attached the PDF, CSV, and HTML files for testing. | ||
|
|
||
| Regards, | ||
| Test Sender | ||
|
|
||
| --BOUNDARY123 | ||
| Content-Type: application/pdf | ||
| Content-Disposition: attachment; filename="test.pdf" | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| JVBERi0xLjQKMSAwIG9iago8PAovVHlwZSAvQ2F0YWxvZwovUGFnZXMgMiAwIFIKPj4KZW5k | ||
| b2JqCjIgMCBvYmoKPDwKL1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDEKPj4K | ||
| ZW5kb2JqCjMgMCBvYmoKPDwKL1R5cGUgL1BhZ2UKL1BhcmVudCAyIDAgUgovTWVkaWFCb3gg | ||
| WzAgMCAzMDAgMTQ0XQovQ29udGVudHMgNCAwIFIKPj4KZW5kb2JqCjQgMCBvYmoKPDwKL0xl | ||
| bmd0aCA0NAo+PgpzdHJlYW0KQlQKL0YxIDEyIFRmCjEwMCAxMDAgVGQKKFRlc3QgUERGIEZp | ||
| bGUpIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKeHJlZgowIDUKMDAwMDAwMDAwMCA2NTUzNSBm | ||
| IAowMDAwMDAwMDEwIDAwMDAwIG4gCjAwMDAwMDAwNTMgMDAwMDAgbiAKMDAwMDAwMDEwMCAw | ||
| MDAwMCBuIAowMDAwMDAwMTc1IDAwMDAwIG4gCnRyYWlsZXIKPDwKL1NpemUgNQovUm9vdCAx | ||
| IDAgUgo+PgpzdGFydHhyZWYKMjUwCiUlRU9G | ||
|
|
||
| --BOUNDARY123 | ||
| Content-Type: text/csv | ||
| Content-Disposition: attachment; filename="test.csv" | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| bmFtZSxhZ2UKSm9obiwzMApBbGljZSwyNQ== | ||
|
|
||
| --BOUNDARY123 | ||
| Content-Type: text/html | ||
| Content-Disposition: attachment; filename="test.html" | ||
| Content-Transfer-Encoding: base64 | ||
|
|
||
| PGh0bWw+Cjxib2R5PkhlbGxvIFdvcmxkPC9ib2R5Pgo8L2h0bWw+ | ||
|
|
||
| --BOUNDARY123-- |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.