本文整理汇总了Java中com.icegreen.greenmail.user.GreenMailUser类的典型用法代码示例。如果您正苦于以下问题:Java GreenMailUser类的具体用法?Java GreenMailUser怎么用?Java GreenMailUser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GreenMailUser类属于com.icegreen.greenmail.user包,在下文中一共展示了GreenMailUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMailReceivedBySubject
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Check mail folder for an email using subject.
*
* @param emailSubject Email subject
* @param folder mail folder to check for an email
* @param protocol protocol used to connect to the server
* @return whether mail received or not
* @throws MessagingException if we're unable to connect to the store
*/
private static boolean isMailReceivedBySubject(String emailSubject, String folder, String protocol,
GreenMailUser user) throws MessagingException {
boolean emailReceived = false;
Folder mailFolder;
Store store = getConnection(user, protocol);
try {
mailFolder = store.getFolder(folder);
mailFolder.open(Folder.READ_WRITE);
SearchTerm searchTerm = new AndTerm(new SubjectTerm(emailSubject), new BodyTerm(emailSubject));
Message[] messages = mailFolder.search(searchTerm);
for (Message message : messages) {
if (message.getSubject().contains(emailSubject)) {
log.info("Found the Email with Subject : " + emailSubject);
emailReceived = true;
break;
}
}
} finally {
if (store != null) {
store.close();
}
}
return emailReceived;
}
示例2: createTestMessages
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
public void createTestMessages() {
try {
GreenMailUser user = greenMail.setUser(TEST_RECIP, "password");
final String subject = GreenMailUtil.random();
final String body = GreenMailUtil.random();
user.deliver(createMimeMessage("[email protected]", subject, body, null));
user.deliver(createMimeMessage("[email protected]", "Great stuff cheap!", "body", null));
user.deliver(createMimeMessage("[email protected]", "Happening this month", "stuff", null));
user.deliver(createMimeMessage("[email protected]", "Get certified today!", "Cheap!", null));
user.deliver(createMimeMessage("[email protected]", "It's been a long time!", "Let's talk", null));
user.deliver(createMimeMessage("[email protected]", "The Sound of Drums", "boom boom boom",
Date.from(LocalDate.now().minusYears(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));
Session imapSession = greenMail.getImap().createSession();
Store store = imapSession.getStore("imap");
store.connect(TEST_RECIP, "password");
Folder defaultFolder = store.getDefaultFolder();
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Folder ads = defaultFolder.getFolder("Ads");
ads.create(Folder.HOLDS_MESSAGES);
Folder spam = defaultFolder.getFolder("Spam");
spam.create(Folder.HOLDS_MESSAGES);
} catch (MessagingException ex) {
Logger.getLogger(TestMailUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例3: deleteAllEmails
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Delete all emails in the inbox.
*
* @param protocol protocol used to connect to the server
* @throws MessagingException if we're unable to connect to the store
*/
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
Folder inbox = null;
Store store = getConnection(user, protocol);
try {
inbox = store.getFolder(EMAIL_INBOX);
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
log.info("Deleted email Subject : " + message.getSubject());
}
} finally {
if (inbox != null) {
inbox.close(true);
}
if (store != null) {
store.close();
}
}
}
示例4: isMailReceived
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Check whether email received by reading the emails.
*
* @param protocol to connect to the store
* @param user whose mail store should be connected
* @param subject the subject of the mail to search
* @return
* @throws MessagingException when unable to connect to the store
*/
public static boolean isMailReceived(String protocol, GreenMailUser user, String subject)
throws MessagingException {
Store store = getConnection(user, protocol);
Folder folder = store.getFolder(EMAIL_INBOX);
folder.open(Folder.READ_ONLY);
boolean isReceived = false;
Message[] messages = folder.getMessages();
for (Message message : messages) {
if (message.getSubject().contains(subject)) {
log.info("Found the Email with Subject : " + subject);
isReceived = true;
break;
}
}
return isReceived;
}
示例5: getUserByEmail
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
public GreenMailUser getUserByEmail(String email)
{
GreenMailUser ret = getUser(email);
if (null == ret)
{
for (GreenMailUser user : userMap.values())
{
// TODO: NPE!
if (user.getEmail().trim().equalsIgnoreCase(email.trim()))
{
return user;
}
}
}
return ret;
}
示例6: test
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* The login method.
*
*/
public boolean test(String userid, String password)
{
try
{
authenticationService.authenticate(userid, password.toCharArray());
String email = null;
if (personService.personExists(userid))
{
NodeRef personNodeRef = personService.getPerson(userid);
email = (String) nodeService.getProperty(personNodeRef, ContentModel.PROP_EMAIL);
}
GreenMailUser user = new AlfrescoImapUser(email, userid, password);
addUser(user);
}
catch (AuthenticationException ex)
{
logger.error("IMAP authentication failed for userid: " + userid);
return false;
}
return true;
}
示例7: listSubscribedMailboxes
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Returns an collection of subscribed mailboxes. To appear in search result mailboxes should have
* {http://www.alfresco.org/model/imap/1.0}subscribed property specified for user. Method searches
* subscribed mailboxes under mount points defined for a specific user. Mount points include user's
* IMAP Virtualised Views and Email Archive Views. This method serves LSUB command of the IMAP protocol.
*
* @param user User making the request
* @param mailboxPattern String name of a mailbox possible including a wildcard.
* @return Collection of mailboxes matching the pattern.
* @throws com.icegreen.greenmail.store.FolderException
*/
public Collection<MailFolder> listSubscribedMailboxes(GreenMailUser user, String mailboxPattern)
throws FolderException
{
try
{
AlfrescoImapUser alfrescoUser = new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword());
return registerMailboxes(imapService.listMailboxes(alfrescoUser, getUnqualifiedMailboxPattern(
alfrescoUser, mailboxPattern), true));
}
catch (Throwable e)
{
logger.debug(e.getMessage(), e);
throw new FolderException(e.getMessage());
}
}
示例8: renameMailbox
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Renames an existing mailbox. The specified mailbox must already exist, the requested name must not exist
* already but must be able to be created and the user must have rights to delete the existing mailbox and
* create a mailbox with the new name. Any inferior hierarchical names must also be renamed. If INBOX is renamed,
* the contents of INBOX are transferred to a new mailbox with the new name, but INBOX is not deleted.
* If INBOX has inferior mailbox these are not renamed. This method serves RENAME command of the IMAP
* protocol. <p/> Method searches mailbox under mount points defined for a specific user. Mount points
* include user's IMAP Virtualised Views and Email Archive Views.
*
* @param user User making the request.
* @param oldMailboxName String name of the existing folder
* @param newMailboxName String target new name
* @throws com.icegreen.greenmail.store.FolderException if an existing folder with the new name.
* @throws AlfrescoImapFolderException if user does not have rights to create the new mailbox.
*/
public void renameMailbox(GreenMailUser user, String oldMailboxName, String newMailboxName) throws FolderException, AuthorizationException
{
try
{
AlfrescoImapUser alfrescoUser = new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword());
String oldFolderPath = getUnqualifiedMailboxPattern(alfrescoUser,
oldMailboxName);
String newFolderpath = getUnqualifiedMailboxPattern(alfrescoUser, newMailboxName);
imapService.renameMailbox(alfrescoUser, oldFolderPath, newFolderpath);
if (folderCache != null)
{
folderCache.remove(oldFolderPath);
folderCache.remove(newFolderpath);
}
}
catch (Throwable e)
{
logger.debug(e.getMessage(), e);
throw new FolderException(e.getMessage());
}
}
示例9: deleteMailbox
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Deletes an existing MailBox. Specified mailbox must already exist on this server, and the user
* must have rights to delete it. <p/> This method serves DELETE command of the IMAP protocol.
*
* @param user User making the request.
* @param mailboxName String name of the target
* @throws com.icegreen.greenmail.store.FolderException if mailbox has a non-selectable store with children
*/
public void deleteMailbox(GreenMailUser user, String mailboxName) throws FolderException, AuthorizationException
{
try
{
AlfrescoImapUser alfrescoUser = new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword());
String folderPath = getUnqualifiedMailboxPattern(alfrescoUser, mailboxName);
imapService.deleteMailbox(alfrescoUser, folderPath);
if (folderCache != null)
{
folderCache.remove(folderPath);
}
}
catch (Throwable e)
{
logger.debug(e.getMessage(), e);
throw new FolderException(e.getMessage());
}
}
示例10: getFolder
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Returns a reference to an existing Mailbox. The requested mailbox must already exists on this server and the
* requesting user must have at least lookup rights. <p/> It is also can be used by to obtain hierarchy delimiter
* by the LIST command: <p/> C: 2 list "" "" <p/> S: * LIST () "." "" <p/> S: 2 OK LIST completed.
* <p/>
* Method searches mailbox under mount points defined for a specific user. Mount points include user's IMAP
* Virtualised Views and Email Archive Views.
*
* @param user User making the request.
* @param mailboxName String name of the target.
* @return an Mailbox reference.
*/
public MailFolder getFolder(GreenMailUser user, String mailboxName)
{
AlfrescoImapUser alfrescoUser = new AlfrescoImapUser(user.getEmail(), user.getLogin(), user.getPassword());
String folderPath = getUnqualifiedMailboxPattern(
alfrescoUser, mailboxName);
if (folderCache == null)
{
registerMailBox(imapService.getOrCreateMailbox(alfrescoUser, mailboxName, true, false));
}
AlfrescoImapFolder result = folderCache.get(folderPath);
// if folder isn't in cache then add it via registerMailBox method
return result != null ? result : registerMailBox(imapService.getOrCreateMailbox(alfrescoUser, mailboxName, true, false));
}
示例11: doProcess
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* @see CommandTemplate#doProcess
*/
protected void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session)
throws ProtocolException {
String userid = parser.astring(request);
String password = parser.astring(request);
parser.endLine(request);
if (session.getUserManager().test(userid, password)) {
GreenMailUser user = session.getUserManager().getUser(userid);
session.setAuthenticated(user);
response.commandComplete(this);
} else {
response.commandFailed(this, "Invalid login/password");
}
}
示例12: deleteMailbox
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* @see ImapHostManager#deleteMailbox
*/
public void deleteMailbox(GreenMailUser user, String mailboxName)
throws FolderException, AuthorizationException {
MailFolder toDelete = getFolder(user, mailboxName, true);
if (store.getChildren(toDelete).isEmpty()) {
toDelete.deleteAllMessages();
toDelete.signalDeletion();
store.deleteMailbox(toDelete);
} else {
if (toDelete.isSelectable()) {
toDelete.deleteAllMessages();
store.setSelectable(toDelete, false);
} else {
throw new FolderException("Can't delete a non-selectable store with children.");
}
}
}
示例13: getQualifiedMailboxName
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Convert a user specified store name into a server absolute name.
* If the mailboxName begins with the namespace token,
* return as-is.
* If not, need to resolve the Mailbox name for this user.
* Example:
* <br> Convert "INBOX" for user "Fred.Flinstone" into
* absolute name: "#user.Fred.Flintstone.INBOX"
*
* @return String of absoluteName, null if not valid selection
*/
private String getQualifiedMailboxName(GreenMailUser user, String mailboxName) {
String userNamespace = user.getQualifiedMailboxName();
if ("INBOX".equalsIgnoreCase(mailboxName)) {
return USER_NAMESPACE + HIERARCHY_DELIMITER + userNamespace +
HIERARCHY_DELIMITER + INBOX_NAME;
}
if (mailboxName.startsWith(NAMESPACE_PREFIX)) {
return mailboxName;
} else {
if (mailboxName.length() == 0) {
return USER_NAMESPACE + HIERARCHY_DELIMITER + userNamespace;
} else {
return USER_NAMESPACE + HIERARCHY_DELIMITER + userNamespace +
HIERARCHY_DELIMITER + mailboxName;
}
}
}
示例14: execute
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
public void execute(Pop3Connection conn, Pop3State state,
String cmd) {
GreenMailUser user = state.getUser();
if (user == null) {
conn.println("-ERR USER required");
return;
}
String[] args = cmd.split(" ");
if (args.length < 2) {
conn.println("-ERR Required syntax: PASS <username>");
return;
}
try {
String pass = args[1];
state.authenticate(pass);
conn.println("+OK");
} catch (Exception e) {
conn.println("-ERR Authentication failed: " + e);
}
}
示例15: getConnection
import com.icegreen.greenmail.user.GreenMailUser; //导入依赖的package包/类
/**
* Get the connection to a mail store
*
* @param user whose mail store should be connected
* @param protocol protocol used to connect
* @return
* @throws MessagingException when unable to connect to the store
*/
private static Store getConnection(GreenMailUser user, String protocol) throws MessagingException {
Properties props = new Properties();
Session session = Session.getInstance(props);
int port;
if (PROTOCOL_POP3.equals(protocol)) {
port = 3110;
} else if (PROTOCOL_IMAP.equals(protocol)) {
port = 3143;
} else {
port = 3025;
props.put("mail.smtp.auth", "true");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "localhost");
props.put("mail.smtp.port", "3025");
}
URLName urlName = new URLName(protocol, BIND_ADDRESS, port, null, user.getLogin(), user.getPassword());
Store store = session.getStore(urlName);
store.connect();
return store;
}