All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nervousync.mail.protocol.impl.POP3Protocol Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
/*
 * Licensed to the Nervousync Studio (NSYC) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.nervousync.mail.protocol.impl;

import jakarta.mail.Folder;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import org.eclipse.angus.mail.pop3.POP3Folder;
import org.nervousync.commons.Globals;
import org.nervousync.proxy.ProxyConfig;
import org.nervousync.mail.operator.ReceiveOperator;
import org.nervousync.mail.protocol.BaseProtocol;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 

Implements class of JavaMail POP3 protocol

*

JavaMail的IMAP协议类

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Jul 31, 2012 20:08:48 $ */ public final class POP3Protocol extends BaseProtocol implements ReceiveOperator { /** * Serial version UID * 序列化UID */ private static final long serialVersionUID = -8698112033277399242L; /** *

Constructor method for POP3Protocol

*

POP3Protocol构造方法

* * @param secureName Secure config name * 安全配置名称 * @param proxyConfig Proxy configure information * 代理服务器配置信息 */ public POP3Protocol(final String secureName, final ProxyConfig proxyConfig) { super(secureName, proxyConfig); this.hostParam = "mail.pop3.host"; this.portParam = "mail.pop3.port"; this.connectionTimeoutParam = "mail.pop3.connectiontimeout"; this.timeoutParam = "mail.pop3.timeout"; } /** *

Read UID string by given folder and message instance

*

根据给定的电子邮件目录实例对象和邮件信息实例对象读取唯一识别ID字符串

* * @param folder E-mail folder instance * 电子邮件目录实例对象 * @param message E-mail message instance * 电子邮件信息实例对象 * * @return Read UID string * 读取的唯一识别ID字符串 * * @throws MessagingException * If an error occurs when read UID string * 当读取唯一识别ID字符串时出现异常 */ @Override public String readUID(Folder folder, Message message) throws MessagingException { if (folder instanceof POP3Folder) { return ((POP3Folder) folder).getUID(message); } return Globals.DEFAULT_VALUE_STRING; } /** *

Read E-mail message by given folder and message UID string

*

从给定的电子邮件目录中读取唯一识别ID字符串标识的电子邮件信息

* * @param folder E-mail folder instance * 电子邮件目录实例对象 * @param uid UID string * 唯一标识ID字符串 * * @return Read e-mail message instance * 读取的电子邮件信息实例对象 * * @throws MessagingException * If an error occurs when read UID string * 当读取唯一识别ID字符串时出现异常 */ @Override public Message readMessage(Folder folder, String uid) throws MessagingException { if (folder instanceof POP3Folder) { for (Message msg : folder.getMessages()) { if (((POP3Folder) folder).getUID(msg).equals(uid)) { return msg; } } } return null; } /** *

Read E-mail message list by given folder and message UID string array

*

从给定的电子邮件目录中读取唯一识别ID字符串数组标识的电子邮件信息列表

* * @param folder E-mail folder instance * 电子邮件目录实例对象 * @param uidArrays UID string * 唯一标识ID字符串 * * @return Read e-mail message instance list * 读取的电子邮件信息实例对象列表 * * @throws MessagingException * If an error occurs when read UID string * 当读取唯一识别ID字符串时出现异常 */ @Override public List readMessages(Folder folder, String... uidArrays) throws MessagingException { List messageList = new ArrayList<>(); if (folder instanceof POP3Folder) { List uidList = Arrays.asList(uidArrays); for (Message message : folder.getMessages()) { if (uidList.contains(((POP3Folder)folder).getUID(message))) { messageList.add(message); } } } return messageList; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy