Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Deletes duplicate mails within a specified IMAP folder. If no folder is specified, then list all folders.


I built this program for my own use and thought it might be useful for others. Use it at your own risk. In my case, my server was using the Dovecot implementation on a Linux server. I didn't do anything special outside of standard IMAP usage, though, but from what I hear, GMail's IMAP is a little different than normal IMAP. I've not tested against GMail so use caution there.

I started this program because I have some problem with Thunderbird that when I move 1000s of messages between folders, for some messages I get 2 or 3 duplicates of each. I haven't figured out why or when this occurs, but it has each time I've done this (a few times). I wrote this program to clean up the mess.

The program itself is written in Groovy, and uses Maven (with the GMavenPlus plugin).


Use Maven to build and run the application. There are 5 arguments, the last is optional:

  • Protocol (imap or imaps)
  • Hostname (server name)
  • user name
  • password
  • folder name

If folder name is left out, the program lists folders.

When all 5 parameters are given, the program operates full. But efore deleting messages, the program will display a summary of the number of messages in the folder, the number of duplicates, and give you a chance to list the headers of the messages to be deleted. Only after the "delete" command is entered are the messages deleted.


List folders:

mvn clean compile exec:java -Dexec.args="imaps johndoe password123"

Detect and delete duplicates on "INBOX.Archives":

mvn clean compile exec:java -Dexec.args="imaps johndoe password123 INBOX.Archives"

Other Uses

This application is a pretty simple example of JavaMail usage from the Groovy language. It's also a good example of a simple Groovy program built with Maven using GMavenPlus with JDK 1.7 and invokedynamic enabled. Since it iterates folders and scans messages, it could be altered to delete or find messages based on any criteria you can code.


Apache 2 license (


Deletes duplicate mails within an IMAP folder







No packages published