Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting user does not delete all their mailboxes #312

Closed
davidnewcomb opened this issue Apr 20, 2020 · 1 comment
Closed

Deleting user does not delete all their mailboxes #312

davidnewcomb opened this issue Apr 20, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@davidnewcomb
Copy link
Contributor

Proof:

package com.icegreen.greenmail.standalone;

import java.util.List;
import java.util.Properties;

import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import com.icegreen.greenmail.imap.ImapHostManager;
import com.icegreen.greenmail.store.MailFolder;
import com.icegreen.greenmail.store.StoredMessage;
import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.user.UserManager;
import com.icegreen.greenmail.util.GreenMail;

public class Bug {

	public static void main(String[] args) throws Exception {

		System.setProperty("greenmail.setup.test.smtp", "true");
		System.setProperty("greenmail.setup.test.pop3", "true");
		System.setProperty("greenmail.setup.test.imap", "true");
		System.setProperty("greenmail.auth.disabled", "false");
		System.setProperty("greenmail.hostname", "127.0.0.1");
		System.setProperty("greenmail.verbose", "true");

		final Properties properties = System.getProperties();
		GreenMailStandaloneRunner standalone = new GreenMailStandaloneRunner();
		standalone.doRun(properties);
		GreenMail gm = standalone.getGreenMail();

		UserManager um = gm.getManagers().getUserManager();
		ImapHostManager im = gm.getManagers().getImapHostManager();

		GreenMailUser user = um.createUser("[email protected]", "blar", "b123");
		MailFolder inbox = im.getInbox(user);
		MailFolder otherfolder = im.createMailbox(user, "otherfolder");

		MimeMessage m1 = createMessage(gm, "sub1", "[email protected]", "[email protected]", "blar to dest1");
		MimeMessage m2 = createMessage(gm, "sub2", "[email protected]", "[email protected]", "foo to dest2");

		System.out.println("Storing in inbox");
		inbox.store(m1);
		System.out.println("Storing in otherfolder");
		otherfolder.store(m2);

		um.deleteUser(user);

		List<StoredMessage> messages = im.getAllMessages();

		System.out.println("Total number of mails on server: " + messages.size());
		System.exit(0);

	}

	public static MimeMessage createMessage(GreenMail gm, String subject, String from, String to, String body) {
		MimeMessage mm = null;
		try {
			javax.mail.Session smtpSession = gm.getSmtp().createSession();
			mm = new MimeMessage(smtpSession);
			mm.setRecipients(RecipientType.TO, to);
			mm.setSubject(subject);
			mm.setFrom(from);
			mm.setText(body);
		} catch (MessagingException e) {
			e.printStackTrace();
		}
		return mm;
	}

}

prints

Total number of mails on server: 1

when it should be zero. Deleting a user only deletes their INBOX and ignores their other folders.
The user is deleted and the other folders are orphaned.

(Fixed it already, I'll prepare PR with test case next).

davidnewcomb added a commit to davidnewcomb/greenmail that referenced this issue Apr 20, 2020
@marcelmay marcelmay self-assigned this Apr 20, 2020
@marcelmay marcelmay added the bug label Apr 20, 2020
@marcelmay marcelmay added this to the 1.5.14 milestone Apr 20, 2020
marcelmay pushed a commit that referenced this issue Apr 20, 2020
@marcelmay
Copy link
Member

Thx alot, @davidnewcomb !

marcelmay pushed a commit that referenced this issue Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants