@Grab(group="javax.mail", module="mail", version="latest.integration")
import java.security.*
import java.util.*
import javax.mail.*
import javax.mail.search.*
import javax.mail.internet.*
host = "imap.gmail.com"
port = "993"
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider())
Properties props = new Properties()
props.put("mail.imap.host", host)
props.put("mail.imap.port", port)
props.put("mail.imap.socketFactory.port", port);
props.put("mail.imap.socketFactory.class",
"javax.net.ssl.SSLSocketFactory")
props.put("mail.imap.socketFactory.fallback", "false")
Session session = Session.getDefaultInstance(props,
[
getPasswordAuthentication: {
return new PasswordAuthentication("youraccount@gmail.com",
'yourpassword')
}
] as Authenticator
)
Store store = null
try
{
store = session.getStore("imap")
store.connect()
for( folder in store.getDefaultFolder().list("カスタムラベル") ){
folder.delete(true)
}
}
finally
{
if( store != null )store.close()
}
動作環境
groovy 1.8.0, OpenJDK1.6.0_22
0 件のコメント:
コメントを投稿