A method for packaging, sending and receiving a general attachment of mail
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-30
- Publication Date
- 2026-08-11
AI Technical Summary
[0003]超过普通附件大小上限的文件需要使用链接方式传输和下载,存在链接安全风险
1、大文件附件传输不采用超链接从远端机下载,无需跳转至外部页面查看或下载;
Abstract
Description
Technical Field
[0001] This invention relates to the field of email transmission technology, specifically to a method for encapsulating, sending, and receiving ordinary email attachments. Background Technology
[0002] In the email field, the protocol limit for ordinary attachments is typically between 10 and 50 MB. Attachment data is encoded and encapsulated as part of the MIME type before being transmitted into the email file. Files exceeding this limit are handled as large attachments, which are converted into links embedded in the email file for transmission. Recipients then download the attachments via these links.
[0003] Files exceeding the standard attachment size limit require transmission and download via links, posing a security risk to these links. In some scenarios, it may be desirable to send large attachments via regular email, eliminating embedded links and satisfying most file transfer needs. Summary of the Invention
[0004] The main objective of this invention is to provide a method for encapsulating ordinary email attachments. By using block encoding, compressed transmission, and additional digest verification, the method increases the upper limit of the transmission size of ordinary email attachments, avoids the security risks and external dependency issues caused by excessively large attachment links, and ensures the integrity of attachment data.
[0005] To achieve the above objectives, the present invention provides a method for encapsulating ordinary email attachments, which includes a sending end processing step and a receiving end processing step. The sending end processing steps include: S1: Perform a digest algorithm on the original attachment data to obtain the digest result; S2: Append the digest to the beginning of the original attachment data to form the attachment data to be processed; S3: Divide the attachment data to be processed into blocks according to a preset block size M to obtain multiple consecutive data blocks; S4: Perform Base64 encoding on each data block to form a continuous encoded block; S5: Compress all encoded blocks according to the specified compression method to obtain compressed attachment data; S6: Add a custom attribute tag X-AttrEncode to the attachment attribute area of the email. X-AttrEncode should at least record the encoding method, digest size, compression method and block size M. S7: Encapsulate the attachment attributes containing X-AttrEncode and the compressed attachment data into an email file according to the MIME protocol and send it; The receiving end processing steps include: S8: The receiving end receives the email file, parses it to obtain the attachment attributes and compressed attachment data; S9: Read the X-AttrEncode flag in the attachment attributes to obtain the encoding method, compression method, and block size M; S10: Perform a decompression operation on the compressed attachment data corresponding to the specified compression method to obtain continuous encoded blocks; S11: Decode the encoded block by block according to the block size M and the encoding method to obtain complete data to be verified, including digest and original attachment data; S12: Remove the digest data of the same length as the digest size from the header of the data to be verified to obtain the restored attachment data; S13: Use the digest to perform an integrity check on the restored attachment data. If the check passes, the attachment restoration is complete.
[0006] The present invention also provides a method for sending ordinary email attachments, including: The original attachment data is processed using a digest algorithm to obtain a digest result. The digest is appended to the beginning of the original attachment data to form attachment data to be processed; The attachment data to be processed is divided into blocks according to a preset block size M to obtain multiple consecutive data blocks; Each data block is Base64 encoded separately to form a continuous encoded block; Compress all encoded blocks according to the specified compression method to obtain compressed attachment data; Add a custom attribute marker X-AttrEncode to the attachment attribute area of the email. The X-AttrEncode must record at least the encoding method, digest size, compression method, and block size M. The attachment attributes containing the X-AttrEncode and the compressed attachment data are encapsulated into an email file according to the MIME protocol and then sent.
[0007] The present invention also provides a method for receiving ordinary email attachments, including: Receive email files, parse them to obtain attachment attributes and compressed attachment data; Read the X-AttrEncode flag in the attachment attributes to obtain the encoding method, compression method, and block size M; Perform the corresponding decompression operation on the compressed attachment data to obtain continuous encoded blocks; The encoded blocks are decoded one by one according to the block size M and the encoding method to obtain the complete data to be verified, which includes the digest and the original attachment data. Remove the digest data of the same length as the digest size from the header of the data to be verified to obtain the restored attachment data; The digest is used to perform an integrity check on the restored attachment data. If the check passes, the attachment restoration is complete.
[0008] The beneficial effects of this invention are as follows: 1. Large file attachments are not downloaded from the remote machine via hyperlinks, eliminating the need to redirect to external pages for viewing or downloading; 2. Large attachments are stored together with the email data on the recipient's mail server, no longer relying on external devices; 3. Divide large attachments into data blocks, and encode, transmit, and reassemble them according to the blocks; 4. Use a digest algorithm to verify the integrity of large attachment data; 5. Compress the encoded data blocks to improve transmission efficiency; 6. Use X-AttrEncode to declare information such as encoding, compression, and block size in the attachment properties area to indicate the attachment processing method. Detailed Implementation
[0009] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art can make similar extensions without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0010] Example 1:
[0011] This embodiment provides a method for encapsulating ordinary email attachments, including two complete processes: sending-end processing and receiving-end processing. Specifically, it is shown below: Sending end processing flow S1: The sending end obtains the original attachment data to be transmitted, calls a preset digest algorithm to calculate the original attachment data, and obtains a fixed-length digest result. The digest algorithm can be any one of the MD5, SHA-1, or SHA-256 algorithms, and different algorithms correspond to different lengths of digest results.
[0012] S2: Append the calculated digest data completely to the beginning of the original appendix data to form unprocessed appendix data containing summary information and original data.
[0013] S3: Divide the attachment data to be processed into multiple consecutive data blocks according to the preset block size M. If the length of the last data block is less than the preset block size M, it is retained according to its actual length without zero padding or truncation. The preset block size M ranges from 1MB to 10MB and can be dynamically adjusted according to the total size of the original attachment data: the larger the total size of the original attachment data, the larger the preset block size M, in order to balance the number of blocks and the processing overhead of a single block.
[0014] S4: For each data block obtained after block division, perform Base64 encoding operation independently. After all data blocks are encoded, a continuous sequence of encoded blocks is formed.
[0015] S5: Perform the specified compression operation on the entire sequence of consecutive coded blocks to obtain the compressed appendix data. The specified compression method can be any one of the following algorithms: DEFLATE, GZIP, or LZ4.
[0016] S6: Add a custom attribute tag X-AttrEncode to the attachment attribute area of the email. This tag records all parameters required for attachment processing in key-value pair format, including at least the encoding method, digest size, compression method, and block size M. The corresponding standard key names are EncodeMethod, DigestSize, CompressMethod, and BlockSize, respectively.
[0017] S7: The attachment attribute information containing the above-mentioned X-AttrEncode custom attributes is encapsulated with the compressed attachment data according to the standard MIME protocol to generate a complete email file, and the email file is sent to the mail server.
[0018] Receiver processing flow: S8: The receiving end retrieves the above email file from the mail server, parses the email structure according to the standard MIME protocol, and extracts the attachment attribute information and compressed attachment data.
[0019] S9: Read the X-AttrEncode custom tag from the extracted attachment attribute information, parse the key-value pair data in the tag, and obtain the encoding method, digest size, compression method and block size M used in this attachment transmission.
[0020] S10: Based on the compression method obtained from the parsing, perform the corresponding decompression operation on the compressed attachment data to restore the continuous coded block sequence generated by the sending end.
[0021] S11: Based on the block size M and encoding method obtained from parsing, perform Base64 decoding operation on each block of the restored encoded block sequence, and concatenate all the decoded data blocks in order to obtain the complete data to be verified, including the digest and original attachment data.
[0022] S12: Starting from the beginning of the header of the data to be verified, extract a data segment of the same length as the parsed digest, which will be used as the digest for this verification; the remaining part of the data to be verified is the preliminary restored attachment data.
[0023] The same digest algorithm as the sender is used to recalculate the initially restored attachment data to obtain a new digest result.
[0024] S13: Compare the newly calculated summary result with the digest extracted from the header of the data to be verified: If the two are completely consistent, the integrity verification passes, confirming that the initially restored attachment data is the original attachment data, and the attachment restoration is completed; if the two are inconsistent, the integrity verification fails, the receiving end returns a message indicating that the attachment is corrupt to the sending end, and discards the corrupt attachment data.
[0025] Example 2: This embodiment provides a method for sending ordinary email attachments, which only includes the sending end processing flow and is suitable for email systems or clients that only need to implement the sending end function.
[0026] The sending end performs the following steps: Obtain the original attachment data to be transmitted, and execute the digest algorithm to obtain the digest result; The digest is appended to the beginning of the original attachment data to form the attachment data to be processed. The attachment data to be processed is divided into blocks according to the preset block size M, resulting in multiple consecutive data blocks; Each data block is Base64 encoded separately to form a continuous encoded block; Compress all encoded blocks according to the specified compression method to obtain compressed attachment data; Add a custom attribute marker X-AttrEncode to the attachment attribute area of the email to record the encoding method, digest size, compression method, and block size M; Encapsulate the attachment attributes containing X-AttrEncode and the compressed attachment data into an email file according to the MIME protocol and send it.
[0027] Example 3: This embodiment provides a method for receiving ordinary email attachments, which only includes the receiving end processing flow and is suitable for email systems or clients that only need to implement the receiving end function.
[0028] The receiving end performs the following steps: Receive email files, parse them to obtain attachment attributes and compressed attachment data; Read the X-AttrEncode flag in the attachment attributes to obtain the encoding method, compression method, digest size, and block size M; Perform a decompression operation on the compressed attachment data corresponding to the specified compression method to obtain continuous encoded blocks; The encoded blocks are decoded one by one according to the block size M and the encoding method, and then spliced together to obtain the complete data to be verified, which includes the digest and the original attachment data. Remove the digest data of the same length as the summary from the header of the data to be verified to obtain the restored attachment data; Use the above digest to perform an integrity check on the restored attachment data. If the check passes, the attachment restoration is complete.
[0029] Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
Claims
1. A method for packaging a mail piece with a generic attachment, comprising: This includes processing steps at the sending end and processing steps at the receiving end; The sending end processing steps include: S1: Perform a digest algorithm on the original attachment data to obtain the digest result; S2: Append the digest to the beginning of the original attachment data to form the attachment data to be processed; S3: Divide the attachment data to be processed into blocks according to a preset block size M to obtain multiple consecutive data blocks; S4: Perform Base64 encoding on each data block to form a continuous encoded block; S5: Compress all encoded blocks according to the specified compression method to obtain compressed attachment data; S6: Add a custom attribute tag X-AttrEncode to the attachment attribute area of the email. X-AttrEncode should at least record the encoding method, digest size, compression method and block size M. S7: Encapsulate the attachment attributes containing X-AttrEncode and the compressed attachment data into an email file according to the MIME protocol and send it; The receiving end processing steps include: S8: The receiving end receives the email file, parses it to obtain the attachment attributes and compressed attachment data; S9: Read the X-AttrEncode flag in the attachment attributes to obtain the encoding method, compression method, and block size M; S10: Perform a decompression operation on the compressed attachment data corresponding to the specified compression method to obtain continuous encoded blocks; S11: Decode the encoded block by block according to the block size M and the encoding method to obtain complete data to be verified, including digest and original attachment data; S12: Remove the digest data of the same length as the digest size from the header of the data to be verified to obtain the restored attachment data; S13: Use the digest to perform an integrity check on the restored attachment data. If the check passes, the attachment restoration is complete.
2. A method for sending a mail general attachment, characterized by, include: The original attachment data is processed using a digest algorithm to obtain a digest result. The digest is appended to the beginning of the original attachment data to form attachment data to be processed; The attachment data to be processed is divided into blocks according to a preset block size M to obtain multiple consecutive data blocks; Each data block is Base64 encoded separately to form a continuous encoded block; Compress all encoded blocks according to the specified compression method to obtain compressed attachment data; Add a custom attribute marker X-AttrEncode to the attachment attribute area of the email. The X-AttrEncode must record at least the encoding method, digest size, compression method, and block size M. The attachment attributes containing the X-AttrEncode and the compressed attachment data are encapsulated into an email file according to the MIME protocol and then sent.
3. A method for receiving ordinary email attachments, characterized in that, include: Receive email files, parse them to obtain attachment attributes and compressed attachment data; Read the X-AttrEncode flag in the attachment attributes to obtain the encoding method, compression method, and block size M; Perform the corresponding decompression operation on the compressed attachment data to obtain continuous encoded blocks; According to the block size M and the encoding mode, the encoding block is decoded block by block to obtain complete to-be-verified data containing a digest and original attachment data; The digest data of a length corresponding to the digest size is removed from the head of the to-be-verified data to obtain restored attachment data; The integrity of the restored attachment data is verified by using the digest, and the verification is passed, and the attachment restoration is completed.