mb61ab431c11928 2022-01-26 13:58:36 阅读数:656
????new?FromStringTerm(" zhaopin "),???
????new?SubjectTerm(" Latest position information "));??
3、 The search sender does not contain “ zhaopin “ All mail
[java]? [view plain]( ) [copy]( )
SearchTerm?notTerm?=?new?NotTerm(new?FromStringTerm(" zhaopin "));??
4、 Search all emails received from Monday to today
[java]? [view plain]( ) [copy]( )
Calendar?calendar?=?Calendar.getInstance();??
calendar.set(Calendar.DAY_OF_WEEK,?calendar.get(Calendar.DAY_OF_WEEK?-?(Calendar.DAY_OF_WEEK?-?1))?-?1);??
Date?mondayDate?=?calendar.getTime();??
SearchTerm?comparisonTermGe?=?new?SentDateTerm(ComparisonTerm.GE,?mondayDate);??
SearchTerm?comparisonTermLe?=?new?SentDateTerm(ComparisonTerm.LE,?new?Date());??
SearchTerm?comparisonAndTerm?=?new?AndTerm(comparisonTermGe,?comparisonTermLe);??
5、 Search greater than or equal to 100KB All of your messages
[java]? [view plain]( ) [copy]( )
int?mailSize?=?1024?*?100;??
SearchTerm?intComparisonTerm?=?new?SizeTerm(IntegerComparisonTerm.GE,?mailSize);??
ComparisonTerm Class is often used in date and number comparisons , It uses six constants EQ(=)、GE(>=)、GT(>)、LE(<=)、LT(<)、NE(!=) To represent six different comparison operations .
Complete code :
[java]? [view plain]( ) [copy]( )
package?org.yangxin.study.jm;??
import?java.io.BufferedReader;??
import?java.io.InputStreamReader;??
import?java.util.Calendar;??
import?java.util.Date;??
import?java.util.Properties;??
import?javax.mail.Flags.Flag;??
import?javax.mail.Folder;??
import?javax.mail.Message;??
import?javax.mail.Session;??
import?javax.mail.Store;??
import?javax.mail.URLName;??
import?javax.mail.internet.MimeMessage;??
import?javax.mail.internet.MimeUtility;??
import?javax.mail.search.AndTerm;??
import?javax.mail.search.BodyTerm;??
import?javax.mail.search.ComparisonTerm;??
import?javax.mail.search.FromStringTerm;??
import?javax.mail.search.IntegerComparisonTerm;??
import?javax.mail.search.NotTerm;??
import?javax.mail.search.OrTerm;??
import?javax.mail.search.SearchTerm;??
import?javax.mail.search.SentDateTerm;??
import?javax.mail.search.SizeTerm;??
import?javax.mail.search.SubjectTerm;??
/**?
?*? Search mail ?
?*/??
public?class?SearchMailTest?{??
????public?static?void?main(String[]?args)?throws?Exception?{??
????????Properties?props?=?new?Properties();??
????????props.setProperty("mail.pop3.auth",?"true");??
????????Session?session?=?Session.getInstance(props);??
????????URLName?url?=?new?URLName("pop3",?"pop3.163.com",?110,?null,?"[email protected]",?"yX546900873");??
????????Store?store?=?session.getStore(url);??
????????store.connect();??
????????//? Get inbox ??
????????Folder?folder?=?store.getFolder("INBOX");??
????????//? Open inbox in read-write mode ??
????????folder.open(Folder.READ_WRITE);??
????????Message[]?messages?=?search(folder);??
????????System.out.println(" Inboxes are shared :"?+?folder.getMessageCount()?+?" Messages , Search for "?+?messages.length?+?" Eligible messages !");??
????????//? Resolve messages searched ??
????????POP3ReceiveMailTest.parseMessage(messages);???
????????//? Search all messages according to the criteria entered by the user , And prompt the user whether to delete ??
????????//searchDemo(folder);??
????????folder.close(true);??
????????store.close();??
????}??
????public?static?Message[]?search(Folder?folder)?throws?Exception?{??
????????//? Search for messages with gourmet topics ??
????????String?subject?=?"java train ";??
????????SearchTerm?subjectTerm?=?new?SubjectTerm(subject);??
????????//? Search sender includes Alipay mail. ??
????????SearchTerm?fromTerm?=?new?FromStringTerm(" Alipay ");??
????????//? Search message content contains " Recruitment " The mail ??
????????SearchTerm?bodyTerm?=?new?BodyTerm(" Recruitment ");??
????????//? The search sender does not contain “ zhaopin ” The mail ??
????????SearchTerm?notTerm?=?new?NotTerm(new?FromStringTerm(" zhaopin "));??
????????//? Search from “ zhaopin ”, And the content includes “Java The engineer “ The mail ??
????????SearchTerm?andTerm?=?new?AndTerm(??
????????????????new?FromStringTerm(" zhaopin "),??
????????????????new?BodyTerm("java The engineer "));??
????????//? Search from ” zhaopin “ Or subject contains ” Latest position information “ The mail ??
????????SearchTerm?orTerm?=?new?OrTerm(??
????????????????new?FromStringTerm(" zhaopin "),???
????????????????new?SubjectTerm(" Latest position information "));??
????????//? Search all emails received from Monday to today ??
????????Calendar?calendar?=?Calendar.getInstance();??
????????calendar.set(Calendar.DAY_OF_WEEK,?calendar.get(Calendar.DAY_OF_WEEK?-?(Calendar.DAY_OF_WEEK?-?1))?-?1);??
????????Date?mondayDate?=?calendar.getTime();??
????????SearchTerm?comparisonTermGe?=?new?SentDateTerm(ComparisonTerm.GE,?mondayDate);??
????????SearchTerm?comparisonTermLe?=?new?SentDateTerm(ComparisonTerm.LE,?new?Date());??
????????SearchTerm?comparisonAndTerm?=?new?AndTerm(comparisonTermGe,?comparisonTermLe);??
????????//? Search greater than or equal 100KB All of your messages ??
????????int?mailSize?=?1024?*?100;??
????????SearchTerm?intComparisonTerm?=?new?SizeTerm(IntegerComparisonTerm.GE,?mailSize);??
????????return?folder.search(intComparisonTerm);??
????}??
example : Based on the recipients entered by the user (email Address or name ) And subject as search criteria , And prompt the user whether to delete the searched mail ?
[java]? [view plain]( ) [copy]( )
/**?
?????*? According to the recipient address entered by the user ( Include email Address and name ) And subject as search criteria , And prompt the user whether to delete the searched mail ?
?????*[email protected]?from? The recipient ?
?????*[email protected]?subject? The theme ?
?????*/??
????public?static?void?searchDemo(Folder?folder)?throws?Exception?{??
????????String?notifyMsg?=?" In the inbox "?+?folder.getMessageCount()?+?" Messages . Please select action :\n";??
????????notifyMsg?+=?"1、 Enter the recipient \n"?+?"2、 Enter a topic \n"?+?"3、 Begin your search \n"?+?"4、 sign out ";??
????????System.out.println(notifyMsg);??
????????String?from?=?null;??
????????String?subject?=?null;??
????????BufferedReader?reader?=?new?BufferedReader(new?InputStreamReader(System.in));??
????????String?oper?=?reader.readLine().trim();??
????????while(!(from?!=?null?&&?subject?!=?null))?{??
????????????if?("4".equals(oper))?{??
????????????????System.exit(0);??
ad locum , Due to the interview MySQL More questions , Therefore, it is here to MySQL As an example, summarize and share . But you often have to learn more than that , There is also the use of some mainstream frameworks ,Spring Source code learning ,Mybatis The learning of source code and so on need to be mastered , I've also sorted out these knowledge points
This article has been CODING Open source project :【 A big factory Java Analysis of interview questions + Core summary learning notes + The latest explanation video + Actual project source code 】 Included
copyright:author[mb61ab431c11928],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261358198479.html