Disclosure of Invention
The invention aims to provide a mail attachment restoring method, a system, a computer device and a readable storage medium, which are used for solving the defects that a large amount of cache is required to be consumed, the use of memory is wasted and the restoring efficiency of mail attachments is reduced in the mail attachment restoring method by caching the whole mail and analyzing the whole MIME format in the prior art.
According to one aspect of the present invention, there is provided a mail attachment restoring method including the steps of:
receiving first mail data in a target mail by adopting a buffer area with a preset size, wherein the first mail data comprises data in an attachment of the target mail;
searching whether a preset head identifier exists in the first mail data or not so as to determine whether a head of a mail attachment exists or not according to a searching result;
If the head identifier exists in the first mail data, searching whether a preset tail identifier exists in the first mail data or not;
If the tail identifier exists in the first mail data, decoding the first mail data to obtain the restored attachment of the target mail.
Optionally, the method further comprises:
And if the head identifier does not exist in the first mail data, the first mail data in the cache area is emptied.
Optionally, the method further comprises:
If the head identifier exists in the first mail data and the tail identifier does not exist, determining the position of the first head identifier in the first mail data;
Cutting the mail data content after the first head mark in the first mail data into at least one data block according to the determined position of the first head mark, wherein the at least one data block comprises a first data block, and the data length of the first data block is not greater than the data length of the mail data content after the first head mark and is the maximum value of multiples of a preset value;
Decoding the first data block to obtain a first target data block;
Transmitting the first target data block to a landing program to store the first target data block;
And clearing the first data block in the buffer area and the mail data content before the first head mark in the first mail data.
Optionally, when the data length of the first data block is smaller than the data length of the mail data content after the first header identifier, the at least one data block further includes a second data block, where the second data block is the mail data content remaining after subtracting the mail data content before the first data block and the first header identifier from the first mail data, and after clearing the mail data content before the first header identifier in the first data block and the first mail data in the buffer area, the method further includes:
Receiving second mail data by adopting the cache region, wherein the second mail data comprises data in an attachment of the target mail, and the length of the second mail data is not more than the sum of the length of the first data block and the length of mail data content before the first head mark;
And splicing the second data block with the second mail data to obtain mail splicing data, and searching whether the tail identification exists in the mail splicing data.
Optionally, when the tail identifier does not exist in the mail splice data, the following steps are circularly executed:
Cutting the mail splice data into a third data block and a fourth data block from front to back, wherein the data length of the third data block is equal to the length of the second mail data, and the fourth data block is the content of the mail data which is remained after the mail splice data minus the third data block;
Decoding the third data block, and sending the decoded mail data content to the disc-drop program;
The third data block in the buffer area is emptied, the buffer area is adopted to receive next mail data, the length of the next mail data is not more than the data length of the third data block, and the next mail data comprises data in an attachment of the target mail;
splicing the fourth data block with the next mail data to obtain next mail spliced data;
Searching whether the tail identification exists in the next mail splicing data;
Stopping executing the steps until the tail mark is found.
Optionally, the method further comprises:
when the tail identifier exists in the mail splicing data, decoding the mail data content of the mail splicing data to obtain a second target data block;
transmitting the second target data block to the landing procedure to save the second target data block;
And merging the first target data block and the second target data block to obtain the restored attachment of the target mail.
Optionally, the decoding the first mail data to obtain the restored attachment of the target mail includes:
Decoding the mail data content between the head identifier and the tail identifier in the first mail data to obtain a target mail attachment data block;
And sending the target mail attachment data block to the tray program to obtain the restored attachment of the target mail.
Optionally, the method further comprises:
when the head identifier exists in the data in the attachment of the target mail, the restored target mail comprises an attachment, and the mail data content of the attachment is the mail data content between the head identifier and the tail identifier;
when a plurality of head identifiers exist in the data in the attachments of the target mail, the restored target mail comprises a plurality of attachments, wherein mail data content between every two adjacent head identifiers corresponds to mail data content of one attachment in the plurality of attachments, and mail data content between the last head identifier and the tail identifier corresponds to mail data content of the last attachment in the plurality of attachments.
In order to achieve the above object, the present invention further provides a mail attachment restoring system, which specifically includes the following components:
the receiving module is used for receiving first mail data in the target mail by adopting a buffer area with a preset size, wherein the first mail data comprises data in an attachment of the target mail;
The first searching module is used for searching whether a preset head identifier exists in the first mail data or not so as to determine whether a head of a mail attachment exists or not according to a searching result;
The second searching module is used for searching whether a preset tail identifier exists in the first mail data or not if the head identifier exists in the first mail data;
And the restoring module is used for decoding the first mail data to obtain the restored attachment of the target mail if the tail identifier exists in the first mail data.
In order to achieve the above object, the present invention further provides a computer device, which specifically includes: the mail attachment restoration method comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the processor realizes the steps of the mail attachment restoration method when executing the computer program.
In order to achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the mail attachment restoration method described above.
According to the mail attachment restoring method provided by the invention, first mail data in the target mail is received by adopting a buffer area with a preset size, wherein the first mail data comprises data in an attachment of the target mail; searching whether a preset head identifier exists in the first mail data or not so as to determine whether a head of a mail attachment exists according to a searching result; if the head identifier exists in the first mail data, searching whether a preset tail identifier exists in the first mail data; if the tail identification exists in the first mail data, decoding the first mail data to obtain the restored attachment of the target mail. . The embodiment of the invention determines the mail attachment by searching the head identifier and the tail identifier of the mail attachment, and then directly restores the mail attachment without caching the mail content in the whole MIME format, thereby saving the memory and improving the restoring efficiency of the mail attachment.
Detailed Description
Reference will now be made in detail to exemplary embodiments of the invention, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The embodiments described in the following exemplary inventive examples do not represent all embodiments consistent with the present invention. Rather, they are merely examples of systems and methods that are consistent with aspects of the invention as detailed in the accompanying claims.
The terminology used herein is for the purpose of describing particular inventive embodiments only and is not intended to be limiting of the invention. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used herein to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the invention. The word "if" as used herein may be interpreted as "at … …" or "at … …" or "in response to a determination" depending on the context.
In the description of the present invention, it should be understood that the numerical references before the steps do not identify the order in which the steps are performed, but are merely used to facilitate description of the present invention and to distinguish between each step, and thus should not be construed as limiting the present invention. All other inventive embodiments, which are obtained by a person skilled in the art without making any inventive effort, are intended to fall within the scope of the present invention.
Embodiments of the present invention will be described below with reference to the accompanying drawings.
Referring to fig. 1, an optional application environment schematic diagram of a mail attachment restoring method provided by an embodiment of the present invention is shown, where a user uses a computer device 2 to connect to a server 4 through a network 6 to implement communication with the server 4. The computer device 2 receives the mail data from the server 4, and searches the mail attachment head identifier and the mail attachment tail identifier in the mail data with preset size by caching the mail data with preset size, thereby realizing the restoration of the mail attachment.
Example 1
Referring to fig. 2, a schematic step flow diagram of a mail attachment restoring method according to an embodiment of the present invention is shown. It will be appreciated that the flow charts in embodiments of the present invention are not intended to limit the order in which the steps are performed. The embodiment of the present invention is exemplarily described with the computer device 2 shown in fig. 1 as an execution subject, and the computer device may include a mobile terminal such as a smart phone, a tablet personal computer (tablet personal computer), a laptop computer (laptop computer), and a fixed terminal such as a desktop computer. The method comprises the following steps:
Step S100, a buffer area with a preset size is adopted to receive first mail data in a target mail, wherein the first mail data comprises data in an attachment of the target mail.
Specifically, in practical application, a large mail or a large mail attachment is often encountered, and at this time, a buffer area with a preset size may be used to receive the first mail data in the target mail, where the preset size may be freely set according to needs.
For example, assuming that restoration of a mail attachment is required for 4M mail data, before receiving the mail data, a user sets a buffer area of a preset size, for example: a buffer area of size 2M is set. When the reception of mail data is started, the mail data of the previous 2M is received first.
Step 200, searching whether a preset header identifier exists in the first mail data, so as to determine whether a header of a mail attachment exists according to a searching result.
Specifically, if the preset header identification exists in the first mail data, it is determined that the header of the mail attachment exists, that is, the mail attachment exists, or else, the header of the mail attachment does not exist. The header identification may be a header key, such as "Content-position" attribute.
In an exemplary embodiment, the method may further include:
And if the head identifier does not exist in the first mail data, the first mail data in the cache area is emptied.
For example, if the email data in the buffer area cannot find the preset header identifier "Content-location: attribute", it indicates that the email data in the buffer area does not have email attachment, and at this time, the email data in the buffer area is emptied. After the mail data in the buffer area is emptied, if there is still remaining mail data, continuing to receive the mail data with the next preset size. For example: and after the front 2M mail data in the buffer area is emptied, the rest 2M mail data is continuously received.
Step S300, if the head identifier exists in the first mail data, whether a preset tail identifier exists in the first mail data is searched.
Specifically, if the head identifier exists in the first mail data, it indicates that a mail attachment exists in the first mail data, and at this time, whether a preset tail identifier exists in the first mail data is searched. The tail identification may be an accessory tail terminator, such as "\r\n\r\n".
In an exemplary embodiment, as shown in fig. 3, the method may include:
Step S301, if the head identifier exists in the first mail data and the tail identifier does not exist, determining the position of the first head identifier in the first mail data;
Step S302, according to the determined position of the first head mark, cutting the mail data content after the first head mark in the first mail data into at least one data block, wherein the at least one data block comprises a first data block, and the data length of the first data block is not greater than the data length of the mail data content after the first head mark and is the maximum value of multiples of a preset value;
Step S303, decoding the first data block to obtain a first target data block;
step S304, the first target data block is sent to a landing procedure to save the first target data block;
step S305, empty the first data block in the buffer and the mail data content before the first header identifier in the first mail data.
For example, if a preset header identifier "Content-position: attribute" is found in the received mail data, then it is found whether the tail identifier "\r\n\r\n" exists in the mail data in the buffer. If the tail identifier "\r\n\r\n" cannot be found in the mail data in the buffer area, cutting the mail data content after the first head identifier in the first mail data into at least one data block, wherein the at least one data block comprises a first data block, the data length of the first data block can be smaller than or equal to the data length of the mail data content after the first head identifier, and the data length is the maximum value of multiples of a preset value, for example, when the Base64 is decoded, the preset value can be 4. And performing Base64 decoding on the first data block to obtain a target data block, sending the target data block to a disc-drop program for storage, and finally clearing the first data block in the buffer area and mail data content before the first head mark in the first mail data. According to the embodiment of the invention, the mail data exceeding the preset size is cut, and the cut mail data is decoded to restore the mail attachment, so that the restoration of the mail attachment with any size is realized.
In an exemplary embodiment, as shown in fig. 4, when the data length of the first data block is smaller than the data length of the mail data content after the first header identifier, the at least one data block further includes a second data block, where the second data block is the mail data remaining after subtracting the mail data content before the first data block and the first header identifier from the first mail data, and the flushing the mail data content before the first header identifier in the first data block and the first mail data in the buffer further includes:
Step S311, receiving second mail data by adopting the buffer area, wherein the second mail data comprises data in the attachment of the target mail, and the length of the second mail data is not more than the sum of the length of the first data block and the length of the mail data content before the first head mark;
For example, assuming that the data length in the buffer is 200, the data length of the mail data content before the first header identifier in the first mail data is 103, the sum L of the data lengths of the first data block and the second data block is 97=200-103, the data length L1 of the first data block is not greater than L and is the maximum value of multiples of a preset value, where the preset value may be 4, 96=4x24, and 96<97, and L1 is 96, that is, the data length of the first data block is 96, and the data length of the second data block is 1.
Step S312, splicing the second data block with the second mail data to obtain mail splicing data, and searching whether the tail identifier exists in the mail splicing data.
For example, the buffer area is used to receive the second mail data, for example, the maximum data length in the buffer area is 200, the data length of the second data block is 1, after the first data block in the buffer area and the mail data content before the first header identifier in the first mail data are emptied, the mail data with the data length of 199 can be continuously received, then the second data block is spliced with the continuously received second mail data, and whether the spliced mail data have the preset tail identifier operation "\r\n\r\n.
In an exemplary embodiment, as shown in fig. 5, when the tail identification is not present in the mail splice data, the following steps are performed in a loop:
Step S321, the mail splice data is cut into a third data block and a fourth data block from front to back, the data length of the third data block is equal to the length of the second mail data, and the fourth data block is the mail data content remained after the mail splice data minus the third data block;
step S322, decoding the third data block, and sending the decoded mail data content to the landing program;
Step S323, emptying the third data block in the buffer area, and receiving the next mail data by adopting the buffer area, wherein the length of the next mail data is not greater than the data length of the third data block, and the next mail data comprises the data in the attachment of the target mail;
Step S324, splicing the fourth data block with the next mail data to obtain the next mail spliced data;
step S325, searching whether the tail identifier exists in the next mail splicing data;
and step S326, stopping executing the steps until the tail mark is found.
When the tail identifier does not exist in the mail splicing data, the mail splicing data is cut into a third data block and a fourth data block, the third data block is decoded, the decoded data block is sent to a tray program and continues to receive the next mail data, the fourth data block and the next mail data are spliced, whether a preset tail identifier operation "\r\n\r\n" exists in the spliced mail data or not is continuously searched, and the cycle is performed until the preset tail identifier exists in the target mail data and exits. According to the embodiment of the invention, the buffer area is emptied after the first mail data in the buffer area is decoded, and the second mail data is continuously received and buffered, so that the buffer area is recycled, and only the buffer area with the preset size is used for buffering the mail data in the whole mail attachment restoring process, so that the whole mail data does not need to be buffered at one time, the utilization rate of the buffer area is improved, and the memory is saved.
In an exemplary embodiment, as shown in fig. 6, the step S312 further includes:
step S331, when finding that the tail identifier exists in the mail splice data, decoding mail data content of the mail splice data to obtain a second target data block;
Step S332, sending the second target data block to the landing procedure to save the second target data block;
step S333, merging the first target data block and the second target data block to obtain the restored attachment of the target mail.
If a preset tail identifier "\r\n\r\n" exists in the spliced mail data, decoding mail data content of the mail spliced data to obtain a second target data block, sending the second target data block to a tray program for storage, finally merging the second target data block with the first target data block decoded before to obtain a restored second mail attachment, and clearing the second data block in the buffer area and mail data content before the tail identifier in the second mail data.
Step S400, if the tail identifier exists in the first mail data, decoding the first mail data to obtain the restored attachment of the target mail.
Specifically, when the tail identifier exists in the first mail data, the mail attachment is completely cached, and at the moment, the restored first mail attachment can be obtained by decoding the first mail data. For example, if the tail identifier "\r\n\r\n" exists in the first mail data, base64 decoding is performed on the first mail data, and the decoded data is sent to a landing program for storage, so as to obtain the restored mail attachment. It should be noted that the present invention can be applied to mail protocols such as simple mail transfer Protocol (SIMPLE MAIL TRANSFER Protocol, SMTP), version 3 of post office Protocol (Post Office Protocol, pop 3), internet message access Protocol (INTERNET MESSAGE ACCESS Protocol, IMAP) and the like for restoring mail attachments.
In an exemplary embodiment, as shown in fig. 7, the decoding the first mail data to obtain the restored attachment of the target mail includes:
Step S401, decoding the mail data content between the head mark and the tail mark in the first mail data to obtain a target mail attachment data block;
step S402, sending the target mail attachment data block to the drop program, to obtain the restored attachment of the target mail.
Illustratively, the mail data content between the head identifier and the tail identifier in the first mail data is decoded to obtain a target mail attachment data block, and the target mail attachment data block is sent to the drop program to obtain the restored attachment of the target mail. And after the restored attachment of the target mail is obtained, the mail data in the buffer area is emptied so as to repeatedly use the buffer area to buffer the mail data, thereby improving the buffer utilization rate and saving the memory.
In an exemplary embodiment, when the header identifier exists in the data in the attachment of the target mail, the restored target mail includes an attachment, and the mail data content of the attachment is the mail data content between the header identifier and the trailer identifier;
when a plurality of head identifiers exist in the data in the attachments of the target mail, the restored target mail comprises a plurality of attachments, wherein mail data content between every two adjacent head identifiers corresponds to mail data content of one attachment in the plurality of attachments, and mail data content between the last head identifier and the tail identifier corresponds to mail data content of the last attachment in the plurality of attachments.
When the mail data in the target mail only has one head identifier, the restored attachment of the target mail only has one, and the mail data content between the head identifier and the tail identifier is the mail data content of the attachment. When the mail data in the target mail has two head identifiers, the restored mail data content between the first head identifier and the second head identifier is the mail data content of the first attachment of the target mail, and the mail data content between the second head identifier and the tail identifier is the mail data content of the second attachment of the target mail.
The mail attachment restoring method provided by the invention realizes restoration of the mail attachment by receiving and caching mail data with preset size and decoding the mail data according to the searching result of the preset head mark and the preset tail mark. The embodiment of the invention determines the mail attachment by searching the head identifier and the tail identifier of the mail attachment, and then directly restores the mail attachment without caching the mail content in the whole MIME format, thereby saving the memory and improving the restoring efficiency of the mail attachment.
It should be noted that, because there are multiple mail attachments in the mail data, the multiple mail attachments are distinguished by the preset header identifier, and marked by the preset tail identifier at the end of the last mail attachment, when the tail identifier is found, all the mail attachments are found, and at this time, decoding of the mail data is performed, and then all the mail attachments can be obtained. By the embodiment of the invention, any number of mail attachments can be restored.
Referring to fig. 8, an optional flowchart of a mail attachment restoring method according to an embodiment of the present invention is shown. The user sets a 2M buffer area and receives mail data, and then searches for an attachment header of the mail data. And if the head of the accessory cannot be found, the cache is emptied. If the head of the accessory is found, continuing to find the tail of the accessory. If the head part of the attachment is found but the tail part of the attachment is not found, the mail data is cut into a plurality of data blocks, the data blocks with the lengths smaller than the mail data and the maximum value being a multiple of 4 are subjected to Base64 decoding, then the decoded data blocks in the cache are emptied, and the mail data are continuously received until the tail part of the attachment is found. If the head of the attachment is found and the tail of the attachment is found, the mail data is directly subjected to Base64 decoding, and restored data blocks are sent to a tray program for storage, so that restoration of the mail attachment in the mail data is completed.
Example two
Referring to FIG. 9, a program module diagram of a mail attachment restore system 700 according to an embodiment of the invention is shown. The mail attachment restoration system 700 may be implemented in a computer device, such as a cell phone, tablet personal computer (tablet personal computer), laptop computer (laptop computer), or the like, having data transfer capabilities. In an embodiment of the present invention, the mail attachment restoration system 700 may include or be divided into one or more program modules, where the one or more program modules are stored in a readable storage medium and executed by one or more processors to implement the embodiment of the present invention and implement the mail attachment restoration system 700 described above. Program modules depicted in the embodiments of the present invention are directed to a series of computer program instruction segments capable of performing the specified functions and that are more suitable than the program itself for describing the execution of the mail attachment reduction system 700 in a readable storage medium. In an exemplary embodiment, the mail attachment restoration system 700 includes a receiving module 701, a first lookup module 702, a second lookup module 703, and a restoration module 704. The following description will specifically describe the functions of each program module of the embodiment of the present invention:
The receiving module 701 is configured to receive first mail data in a target mail by using a buffer of a preset size, where the first mail data includes data in an attachment of the target mail.
Specifically, in practical application, a large mail or a large mail attachment is often encountered, and at this time, a buffer area with a preset size may be used to receive the first mail data in the target mail, where the preset size may be freely set according to needs.
For example, assuming that restoration of the mail attachment is required for the mail data of 4M, the receiving module 701 sets a buffer area with a preset size, for example, before receiving the mail data, by a user: a buffer area of size 2M is set. When the reception of mail data is started, the mail data of the previous 2M is received first.
The first searching module 702 is configured to search whether a preset header identifier exists in the first mail data, so as to determine whether a header of a mail attachment exists according to a searching result.
Specifically, if the preset header identification exists in the first mail data, it is determined that the header of the mail attachment exists, that is, the mail attachment exists, or else, the header of the mail attachment does not exist. The header identification may be a header key, such as "Content-position" attribute.
In an exemplary embodiment, the first lookup module 702 is specifically configured to:
And if the head identifier does not exist in the first mail data, the first mail data in the cache area is emptied.
For example, if the email data in the buffer area cannot find the preset header identifier "Content-location: attribute", it indicates that the email data in the buffer area does not have email attachment, and at this time, the email data in the buffer area is emptied. After the mail data in the buffer area is emptied, if there is still remaining mail data, continuing to receive the mail data with the next preset size. For example: and after the front 2M mail data in the buffer area is emptied, the rest 2M mail data is continuously received.
The second searching module 703 is configured to search whether a preset tail identifier exists in the first mail data if the head identifier exists in the first mail data.
Specifically, if the head identifier exists in the first mail data, it indicates that a mail attachment exists in the first mail data, and at this time, whether a preset tail identifier exists in the first mail data is searched. The tail identification may be an accessory tail terminator, such as "\r\n\r\n".
In an exemplary embodiment, the second search module 703 is specifically configured to:
If the head identifier exists in the first mail data and the tail identifier does not exist, determining the position of the first head identifier in the first mail data;
Cutting the mail data content after the first head mark in the first mail data into at least one data block according to the determined position of the first head mark, wherein the at least one data block comprises a first data block, and the data length of the first data block is not greater than the data length of the mail data content after the first head mark and is the maximum value of multiples of a preset value;
Decoding the first data block to obtain a first target data block;
Transmitting the first target data block to a landing program to store the first target data block;
And clearing the first data block in the buffer area and the mail data content before the first head mark in the first mail data.
For example, if a preset header identifier "Content-position: attribute" is found in the received mail data, then it is found whether the tail identifier "\r\n\r\n" exists in the mail data in the buffer. If the tail identifier "\r\n\r\n" cannot be found in the mail data in the buffer area, cutting the mail data content after the first head identifier in the first mail data into at least one data block, wherein the at least one data block comprises a first data block, the data length of the first data block can be smaller than or equal to the data length of the mail data content after the first head identifier, and the data length is the maximum value of multiples of a preset value, for example, when the Base64 is decoded, the preset value can be 4. And performing Base64 decoding on the first data block to obtain a target data block, sending the target data block to a disc-drop program for storage, and finally clearing the first data block in the buffer area and mail data content before the first head mark in the first mail data. According to the embodiment of the invention, the mail data exceeding the preset size is cut, and the cut mail data is decoded to restore the mail attachment, so that the restoration of the mail attachment with any size is realized.
In one embodiment, when the data length of the first data block is smaller than the data length of the mail data content after the first header identification, the at least one data block further includes a second data block, and the second data block is mail data content remaining after subtracting the first data block and the mail data content before the first header identification from the first mail data.
For example, assuming that the data length in the buffer is 200, the data length of the mail data content before the first header identifier in the first mail data is 103, the sum L of the data lengths of the first data block and the second data block is 97=200-103, the data length L1 of the first data block is a maximum value smaller than L and being a multiple of a preset value, where the preset value may be 4, 96=4x24, and 96<97, L1 is 96, that is, the data length of the first data block is 96, and the data length of the second data block is 1.
In an exemplary embodiment, the second search module 703 is specifically further configured to:
Receiving second mail data by adopting the cache region, wherein the second mail data comprises data in an attachment of the target mail, and the length of the second mail data is not more than the sum of the length of the first data block and the length of mail data content before the first head mark;
For example, assuming that the data length in the buffer is 200, the data length of the mail data content before the first header identifier in the first mail data is 103, the sum L of the data lengths of the first data block and the second data block is 97=200-103, the data length L1 of the first data block is not greater than L and is the maximum value of multiples of a preset value, where the preset value may be 4, 96=4x24, and 96<97, and L1 is 96, that is, the data length of the first data block is 96, and the data length of the second data block is 1.
And splicing the second data block with the second mail data to obtain mail splicing data, and searching whether the tail identification exists in the mail splicing data.
For example, the buffer area is used to receive the second mail data, for example, the maximum data length in the buffer area is 200, the data length of the second data block is 1, after the first data block in the buffer area and the mail data content before the first header identifier in the first mail data are emptied, the mail data with the data length of 199 can be continuously received, then the second data block is spliced with the continuously received second mail data, and whether the spliced mail data have the preset tail identifier operation "\r\n\r\n.
In an exemplary embodiment, the second search module 703 is specifically further configured to:
Cutting the mail splice data into a third data block and a fourth data block from front to back, wherein the data length of the third data block is equal to the length of the second mail data, and the fourth data block is the content of the mail data which is remained after the mail splice data minus the third data block;
Decoding the third data block, and sending the decoded mail data content to the disc-drop program;
The third data block in the buffer area is emptied, the buffer area is adopted to receive next mail data, the length of the next mail data is not more than the data length of the third data block, and the next mail data comprises data in an attachment of the target mail;
splicing the fourth data block with the next mail data to obtain next mail spliced data;
Searching whether the tail identification exists in the next mail splicing data;
Stopping executing the steps until the tail mark is found.
When the tail identifier does not exist in the mail splicing data, the mail splicing data is cut into a third data block and a fourth data block, the third data block is decoded, the decoded data block is sent to a tray program and continues to receive the next mail data, the fourth data block and the next mail data are spliced, whether a preset tail identifier operation "\r\n\r\n" exists in the spliced mail data or not is continuously searched, and the cycle is performed until the preset tail identifier exists in the target mail data and exits. According to the embodiment of the invention, the buffer area is emptied after the first mail data in the buffer area is decoded, and the second mail data is continuously received and buffered, so that the buffer area is recycled, and only the buffer area with the preset size is used for buffering the mail data in the whole mail attachment restoring process, so that the whole mail data does not need to be buffered at one time, the utilization rate of the buffer area is improved, and the memory is saved.
In an exemplary embodiment, the second search module 703 is specifically further configured to:
when the tail identifier exists in the mail splicing data, decoding the mail data content of the mail splicing data to obtain a second target data block;
transmitting the second target data block to the landing procedure to save the second target data block;
And merging the first target data block and the second target data block to obtain the restored attachment of the target mail.
If a preset tail identifier "\r\n\r\n" exists in the spliced mail data, decoding mail data content of the mail spliced data to obtain a second target data block, sending the second target data block to a tray program for storage, finally merging the second target data block with the first target data block decoded before to obtain a restored second mail attachment, and clearing the second data block in the buffer area and mail data content before the tail identifier in the second mail data.
And a restoration module 704, configured to decode the first mail data if the tail identifier exists in the first mail data, so as to obtain an attachment of the restored target mail.
Specifically, when the tail identifier exists in the first mail data, the mail attachment is completely cached, and at the moment, the restored first mail attachment can be obtained by decoding the first mail data. For example, if the tail identifier "\r\n\r\n" exists in the first mail data, base64 decoding is performed on the first mail data, and the decoded data is sent to a landing program for storage, so as to obtain the restored mail attachment. It should be noted that the present invention can be applied to mail protocols such as simple mail transfer Protocol (SIMPLE MAIL TRANSFER Protocol, SMTP), version 3 of post office Protocol (Post Office Protocol, pop 3), internet message access Protocol (INTERNET MESSAGE ACCESS Protocol, IMAP) and the like for restoring mail attachments.
In an exemplary embodiment, the reduction module 704 is specifically configured to:
Decoding the mail data content between the head identifier and the tail identifier in the first mail data to obtain a target mail attachment data block;
And sending the target mail attachment data block to the tray program to obtain the restored attachment of the target mail.
Illustratively, the mail data content between the head identifier and the tail identifier in the first mail data is decoded to obtain a target mail attachment data block, and the target mail attachment data block is sent to the drop program to obtain the restored attachment of the target mail. And after the restored attachment of the target mail is obtained, the mail data in the buffer area is emptied so as to repeatedly use the buffer area to buffer the mail data, thereby improving the buffer utilization rate and saving the memory.
In an exemplary embodiment, the mail attachment restoration system 700 is specifically further configured to:
when the head identifier exists in the data in the attachment of the target mail, the restored target mail comprises an attachment, and the mail data content of the attachment is the mail data content between the head identifier and the tail identifier;
when a plurality of head identifiers exist in the data in the attachments of the target mail, the restored target mail comprises a plurality of attachments, wherein mail data content between every two adjacent head identifiers corresponds to mail data content of one attachment in the plurality of attachments, and mail data content between the last head identifier and the tail identifier corresponds to mail data content of the last attachment in the plurality of attachments.
When the mail data in the target mail only has one head identifier, the restored attachment of the target mail only has one, and the mail data content between the head identifier and the tail identifier is the mail data content of the attachment. When the mail data in the target mail has two head identifiers, the restored mail data content between the first head identifier and the second head identifier is the mail data content of the first attachment of the target mail, and the mail data content between the second head identifier and the tail identifier is the mail data content of the second attachment of the target mail.
The mail attachment restoring system 700 provided by the invention realizes restoration of mail attachments by receiving and caching mail data with preset sizes and decoding the mail data according to the search results of preset head identifiers and preset tail identifiers. The embodiment of the invention determines the mail attachment by searching the head identifier and the tail identifier of the mail attachment, and then directly restores the mail attachment without caching the mail content in the whole MIME format, thereby saving the memory and improving the restoring efficiency of the mail attachment.
It should be noted that, because there are multiple mail attachments in the mail data, the multiple mail attachments are distinguished by the preset header identifier, and marked by the preset tail identifier at the end of the last mail attachment, when the tail identifier is found, all the mail attachments are found, and at this time, decoding of the mail data is performed, and then all the mail attachments can be obtained. By the embodiment of the invention, any number of mail attachments can be restored.
Example III
Referring to fig. 10, an embodiment of the invention further provides a hardware architecture diagram of the computer device 800. Such as a smart phone, tablet, notebook, desktop, rack-mounted server, blade, tower, or rack-mounted server (including stand-alone servers, or a server cluster made up of multiple servers) that can execute programs, etc. In the embodiment of the present invention, the computer device 800 is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction. As shown, the computer device 800 includes, but is not limited to, at least a memory 801, a processor 802, and a network interface 803, which can be communicatively coupled to each other via a device bus. Wherein:
In an embodiment of the present invention, the memory 801 includes at least one type of computer-readable storage medium including flash memory, hard disk, multimedia card, card memory (e.g., SD or DX memory, etc.), random Access Memory (RAM), static Random Access Memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some inventive embodiments, the memory 801 may be an internal storage unit of the computer device 800, such as a hard disk or a memory of the computer device 800. In other embodiments of the invention, the memory 801 may also be an external storage device of the computer device 800, such as a plug-in hard disk, a smart memory card (SMART MEDIA CARD, SMC), a Secure Digital (SD) card, a flash memory card (FLASH CARD) or the like, which are provided on the computer device 800. Of course, the memory 801 may also include both internal storage elements of the computer device 800 and external storage devices. In the embodiment of the present invention, the memory 801 is generally used to store an operating device and various application software installed on the computer device 800, for example, the program code of the mail attachment restoring system 700. Further, the memory 801 can also be used to temporarily store various types of data that have been output or are to be output.
The processor 802 may be a central processing unit (Central Processing Unit, CPU), controller, microcontroller, microprocessor, or other voice processing chip in some inventive embodiments. The processor 802 is generally used to control the overall operation of the computer device 800. In the embodiment of the present invention, the processor 802 is configured to execute the program code stored in the memory 801 or process data, for example, execute the program code of the mail attachment restoring system 700, so as to implement the mail attachment restoring method in the embodiments of the present invention.
The network interface 803 may comprise a wireless network interface or a wired network interface, the network interface 803 typically being used to establish a communication connection between the computer apparatus 800 and other electronic devices. For example, the network interface 803 is used to connect the computer device 800 to an external terminal through a network, establish a data transmission channel and a communication connection between the computer device 800 and the external terminal, and the like. The network may be an Intranet (Intranet), the Internet (Internet), a global system for mobile communications (Global System of Mobile communication, GSM), wideband code division multiple access (Wideband Code Division Multiple Access, WCDMA), a 4G network, a 5G network, bluetooth (Bluetooth), wi-Fi, or other wireless or wired network.
It should be noted that fig. 10 only shows a computer device 800 having components 801-803, but it should be understood that not all of the illustrated components are required to be implemented and that more or fewer components may be implemented instead.
In an embodiment of the present invention, the mail attachment restoration system 700 stored in the memory 801 may be further divided into one or more program modules, which are stored in the memory 801 and executed by one or more processors (the processor 802 in the embodiment of the present invention) to perform the mail attachment restoration method of the present invention.
Example IV
Embodiments of the present invention also provide a computer readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, which when executed by a processor, performs a corresponding function. The computer readable storage medium of an embodiment of the present invention is used to store the mail attachment restoration system 700, so as to implement the mail attachment restoration method of the present invention when executed by a processor.
The foregoing description of the embodiment numbers of the present invention is only for the purpose of description, and does not represent the advantages and disadvantages of the embodiment of the present invention.
From the foregoing description of the embodiments, those skilled in the art will clearly understand that the above-described method according to the embodiment of the present invention may be implemented by software plus a necessary general hardware platform, or may be implemented by hardware, but in many cases, the former is a preferred embodiment.
The foregoing is only the preferred embodiments of the present invention and is not intended to limit the scope of the present invention, and all equivalent structures or equivalent processes using the descriptions and the drawings of the present invention or directly or indirectly applied to other related technical fields are included in the scope of the present invention.