As you know, Gmail does not allow sorting letters, in particular by size.
There is a service that marks large letters with a tag -
www.findbigmail.com , but not everyone wants to give it is not clear to whom their password.
I wrote a script (on the groove) that creates the “Big Mail” label and marks it with all letters larger than 4MB in size. In the script, you need to replace the username and password in Gmail, as well as, if you want, the size of "large" emails.
For the script to work in the classpath, there must be jars
from here .
')
The iteration is reportedly slow (1-2 per second), so I put a print of the number of the letter being scanned so that you know that the script is not stuck.
It takes a little time to pick up all the messages even with my quantity (ca. 20,000). But when accessing message attributes (getSize ()), the Message goes to the server.
You can set this up for
Pre Fetch , then the total time may decrease, but the time to receive the list of messages will grow (and seriously) (that is, you will wait without knowing if it is alive at all)
Another interesting point: copyMessages () as applied to Gmail does not copy or transfer anything, but simply adds a label.
I mark messages one by one, so that it does not happen that the script crashed (for example, because the network fell) and did nothing.
In general, there is room for improvement - interactively asking for a name and password, not marking those that are already marked, etc. Who needs - dopilit :)
Do not forget to make IMAP - enable in Settings gmail.
// Mark large email messages in Gmail by "Bim Mail" label. // (c) Pavel :) // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
import java.security.NoSuchProviderException import javax.mail.*
final int BIG_MAIL_SIZE = 2 ** 22 //4Mb final String username = "xxx" final String password = "xxx"
Properties props = System.getProperties () props.setProperty ( "mail.store.protocol" , "imaps" ) props.setProperty ( "mail.imap.socketFactory.class" , "javax.net.ssl.SSLSocketFactory" ) props.setProperty ( "mail.imap.socketFactory.fallback" , "false" )
Folder all, big Store store
try { Session session = Session.getDefaultInstance ( props, null ) store = session.getStore ( "imaps" ) final String mailaddress = "$username@gmail.com"
store.connect ( "imap.gmail.com" , mailaddress, password ) def folderName = "[Gmail]/All Mail" all = store.getFolder ( folderName ) all.open ( Folder.READ_WRITE ) ;
println ( "Creating BigMail ..." ) big = store.getFolder ( "BigMail" ) if ( big.create ( Folder.HOLDS_MESSAGES )) println "Ok." else println "Failure. Already exists?"
big.open ( Folder.READ_WRITE ) ;
println "Downloading from folder $folderName ...." List<Message> messages = all.getMessages () println "Got ${messages.size()} messages"
int count = 0 messages.each { int size = it.getSize () ;
if ( size > BIG_MAIL_SIZE ) { println "$count: Big mail: ${it.getSubject()} (${it.getSize()})" all.copyMessages ([ it ] .toArray ( new Message [ 1 ]) , big )
} else { println count } count++
}
} catch ( NoSuchProviderException e ) { e.printStackTrace () ; System.exit ( 1 ) ; } catch ( MessagingException e ) { e.printStackTrace () ; System.exit ( 2 ) ; } finally { // Close connection all.close ( false ) big.close ( false ) store.close () }
|
Java2html
|