Commit graph

38 commits

Author SHA1 Message Date
769783f037
Refactor error handling in eml parser
Removed redundant error checking in address parsing as netmail.ParseAddressList already performs necessary checks. Added a default error return for unsupported content disposition types to improve robustness.
2024-10-24 16:42:00 +02:00
9f1e1976fe
Fix assignment in error handling for EML parsing function
Correct the variable assignment in the `if err` statement to ensure proper error handling. This change eliminates a potential bug where the wrong variable might be used.
2024-10-24 14:49:24 +02:00
127cfdf2bc
Fix error variable declaration in eml.go
The error variable declaration has been corrected from "if err := parseEML(...)" to "if err = parseEML(...)". This change ensures consistency with the rest of the error handling code in the file.
2024-10-24 13:20:09 +02:00
a638090d0e
Fix typo in multipart comment
Corrected the spelling of "seperately" to "separately" in a comment explaining the parsing of multipart/related and multipart/alternative parts.
2024-10-16 10:38:40 +02:00
2c1082fe42
Enhance EML parsing function documentation
Added detailed doc comments to EML parsing functions, specifying parameters, return values, and providing thorough explanations of functionalities to improve code understandability and maintainability. This helps future developers and users comprehend the usage and behavior of these functions more effectively.
2024-10-06 13:51:36 +02:00
5653df373b
Add periods to end of go doc comments
Ensure all go doc comments in eml.go have consistent punctuation by adding periods to the end of each comment. This improves code readability and maintains uniformity in the documentation style.
2024-10-05 11:11:17 +02:00
69b1dc2359
Refactor: Handle missing Content-Type as plain text
Added a new example email and modified tests to include an RFC 5322 format. Refactored the code to handle cases where the Content-Type header is missing by defaulting to plain text (7bit, US-ASCII). Deleted redundant test cases that no longer apply.
2024-08-02 15:30:46 +02:00
ed93e51cec
Add support for 7bit and 8bit encodings in EML parsing
Enhanced EML parsing to handle 7bit and 8bit content transfer encodings. Updated related test cases to verify the correct handling of these encodings. This ensures compliance with RFC2045 for defaulting to 7bit when no encoding is specified.
2024-08-01 10:55:28 +02:00
4e7082a540
Rename WithContentID to WithFileContentID
In the eml.go and file.go files, the function WithContentID has been renamed to WithFileContentID. This aligns more accurately with the function purpose, which is to set the content ID for a File object.
2024-06-28 13:49:21 +02:00
68d0fe9cd3
Remove debug print statement from eml.go
The debug print statement that outputs the content type of the email has been removed from eml.go. This change improves code cleanliness and avoids unnecessary console output in production.
2024-06-28 13:33:57 +02:00
0bf3f73e9b
Update comment in eml.go for parsing multipart messages
The comment in the eml.go file was extended to include the possibility of 'Multipart/alternative' parts. Previously, it only mentioned 'Multipart/related' parts. The actual code functionality remains unchanged, this is purely a clarification in the documentation.
2024-06-28 13:28:57 +02:00
fcc5209852
Add handling for multipart/alternative content type
The EML parser now includes logic to manage 'multipart/alternative' content types. This adjustment is made within the section handling 'multipart/related' parts, allowing for better handling and parsing of varying content types.
2024-06-28 13:28:09 +02:00
84e6275cb2
Add base64 encoding support to email attachments
The updated code adds base64 encoding support to email attachments and inline content in eml.go. It does this by introducing a new dataReader which uses a base64 decoder if the content transfer encoding is base64. With this update, attachments with base64 content will be correctly decoded when processed.
2024-06-28 11:54:30 +02:00
8b1208949f
Fix multipart header parsing in eml.go
The commit modifies the parseMultiPartHeader function to handle optional fields accurately. The delimiter was changed from "; " to ";" and whitespace is being trimmed from the start of optional fields to ensure correct splitting and mapping.
2024-06-25 10:59:04 +02:00
faab5323fd
Fix erroneous header name in error message
The error message previously referenced a constant 'HeaderTo' which might not always be the header being parsed. The commit replaces this with 'addrHeader', significantly improving the accuracy of error messages.
2024-06-25 09:47:12 +02:00
0cec8a28f7
Refactor EML parsing into a single function
The previous separate parsing of EML headers and body parts has been refactored into a single function, parseEML. This change simplifies the operations in the readEML and makes the code cleaner by reducing repetition.
2024-06-24 14:30:07 +02:00
70c9387003
Add error handling for unknown content types in eml.go
The update adds a case to the switch clause in eml.go for properly handling unknown content types. An error will now be returned when the media type of the body to be parsed is not recognized, increasing the robustness of the system.
2024-06-24 13:41:48 +02:00
bb33c4a921
Add support for multipart/related EML parsing
This update expands the EML parser to support multipart/related content types. It also includes relevant error handling and creates a specific routine for parsing multipart/related parts separately. Furthermore, adjustments were made to avoid processing headers unnecessarily when TypeMultipartMixed is used. The diff also shows some refactoring for clearer error messages and cleaner code.
2024-06-22 14:13:26 +02:00
52ef13a5d5
Refactor test cases and remove content print statement
The content print statement in eml.go was removed to optimize code readability and performance. In addition, several assertions in the test cases of eml_test.go were corrected for string formatting errors and a new test case was added for handling emails with attachments. These changes aim to enhance the robustness of tests for email encoding and decoding operations.
2024-06-19 15:25:37 +02:00
e95799ad60
Refactor attachment and embed parsing in EML
The EML parsing has been refactored to separate the handling of attachments and embeds into a new helper function. This improves the organization of the code, makes it easier to understand and helps to better manage error handling and resource closing.
2024-06-19 14:41:13 +02:00
85c07c22cc
Refactor multipart parsing in eml.go
The code is refactored to improve multipart parsing in EML. The `parseEMLMultipartAlternative` function is updated to `parseEMLMultipart` for more general utilization. This involves iterating through the parts of a multipart message until content disposition is found and appended. A new function `parseMultiPartHeader` is introduced to parse multipart header and handle charset more sensibly.
2024-06-19 13:57:00 +02:00
29305675d6
Refactor EML encoding and content-type parsing to separate functions
The commit includes extraction of blocks of code related to EML message encoding and content-type parsing into their own separate functions. By doing so, it improves code readability and maintainability.
2024-06-19 10:52:09 +02:00
481fc1d48c
Refactor variable names in eml.go for clarity
Variable names in eml.go have been refactored for better readability and understanding. Shortened abbreviations have been expanded into meaningful names, and complex object names have been made simpler, making it easier to understand their role within the codebase. Cooperative variable names will improve maintainability and ease future development. This is a follow up to #179 which didn't consider this branch.
2024-05-27 10:59:38 +02:00
3facbde703
Add new content types and refactor message writer
Introduced "multipart/mixed" and "multipart/related" content types in encoding.go and updated msgwriter.go to accommodate these. Adjustments made in related tests for these new types. Additionally, removed unnecessary print statements and improved multipart alternative parsing in eml.go.
2024-02-10 13:36:42 +01:00
59e85809f7
Refactor multipart encoding handling and improve content parsing
Refactored the processing of multipart encoding to be robust and easily maintainable. The changes include setting 'QP' encoding as default when the Content-Transfer-Encoding header is empty, accounting for the removal of this header by the standard Go multipart package. Also, parser functions for content type and charset are now independently handling the headers, replacing the split-string approach, thus improving efficiency and code readability.
2024-02-10 13:22:38 +01:00
53566a93cd
Add content type, charset processing and refactor encoding process
Extended the settings for content type and charset from headers. Also, refactored the handling of encoding types - 'QP' and 'B64' - within the mail header and body parsing sections. The process of handling encoding for plain type mail specifically is now encapsulated in a new function, parseEMLBodyPlain. These changes enhance code readability, maintainability, and error handling efficiency.
2024-02-09 15:56:39 +01:00
4202f705a0
Refactor variable naming and multipart parse function in eml.go
The variable names "mbbuf", "mt", and "par" have been renamed to "bodybuf", "mediatype", and "params" respectively, for clarification. Moreover, the multipart parsing block within the parseEMLBodyParts function was extracted into its own function, parseEMLMultipartAlternative, for improved code structure and readability.
2024-02-09 12:34:11 +01:00
60222c95e7
Add multipart message parsing in eml.go
This commit introduces the ability to handle multipart messages within the eml.go file. It reads individual parts of multipart messages, sets the encoding and content for each part, and implements error handling for potential issues like a missing boundary tag or difficulties acquiring the next part of a multipart message.
2024-01-22 17:49:58 +01:00
f9140ce90e
Add parsing of EML from string and reader
Added two new methods `EMLToMsgFromString` and `EMLToMsgFromReader` in "eml.go". They allow EML parsing directly from a given string and a reader object, increasing overall functionality and versatility of the EML parsing process. This will enable the users to parse EML documents more flexibly."
2023-10-31 11:45:09 +01:00
2bba7b902b
Updated error handling and encoding comparison in EML parsing
This commit changes the usage of error value and improves the string comparison for encoding types in EML file parsing. It ensures file closure after read operations to avoid memory leaks. Error messages are made dynamic for improved error reporting. Comments on function has also been made more descriptive.
2023-10-17 10:41:42 +02:00
54ccb80925
Add base64 support in email parser
Implemented base64 encoding support in the email parser. This addition allows the parser to read and decode base64 encoded emails.
2023-10-13 16:27:57 +02:00
a3b3deb467
#145: Support for quoted-printable encoding in email parser
Added support for quoted-printable encoding in email parser to increase its functionality. The change includes a case handling feature for 'EncodingQP' and related conversions to allow for proper message body reading and encoding setting. This improves the robustness and the scope of email content types that the parser can handle."
2023-10-13 16:04:07 +02:00
e7c717d0fc
"Rename Mime10 to MIME10 in codebase
Renamed field 'Mime10' to 'MIME10' across multiple files for canonical representation and consistency with standard MIME naming format in the protocol."
2023-10-13 15:23:28 +02:00
07a3450103
Added SPDX license header 2023-10-13 15:08:53 +02:00
f60b689b03
Refactor EML file parsing and header extraction
We can no parse simple mails (multipart is not working yet). The existing implementation was made more efficient by refactoring the EML file parsing and header extraction mechanism. Added 'strings' and 'bytes' packages to facilitate these changes. Previously, headers and body were parsed separately which was unnecessarily complex and increased the chance of errors. Now, with the new function 'readEML' and the helper function 'parseEMLBodyParts', we are able to parse headers and body together which not only simplifies the code but also increases its reliability. Specifically, 'bytes.Buffer' now helps us capture body while parsing, which removes need for separate handling. Additionally, certain headers like 'charset' and body types are also accounted for in the new implementation, enhancing the completeness of information extracted from EML files.
2023-10-13 15:06:28 +02:00
3d50370a4c
Extract and set charset from email content type
The diff modifies how the email library handles the extraction of the mime media type from an email header. It uses the mime.ParseMediaType function to parse the content type header. The function gives back the media type as a string and a mapping of different associated parameters. This mapping was previously just printed, but now the charset parameter is also used for setting the charset of the email if it exists.
2023-09-27 11:29:58 +02:00
d733b6e17d
Making slight progress on EML parsing 2023-09-21 13:50:36 +02:00
d8d2a6e714
Add EML parsing functionality to mail package
Added two new functions `EMLToMsg` and `readEML` to the `mail` package. `EMLToMsg` function opens and parses a .eml file and returns a pre-filled Msg pointer. `readEML` opens an EML file and uses net/mail to parse the header and body. These changes are made to provide support for EML file parsing, which is a common requirement in many email-based applications.
2023-09-15 13:16:14 +02:00