本文整理汇总了Java中javax.mail.Folder.getType方法的典型用法代码示例。如果您正苦于以下问题:Java Folder.getType方法的具体用法?Java Folder.getType怎么用?Java Folder.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.Folder
的用法示例。
在下文中一共展示了Folder.getType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveByFolder
import javax.mail.Folder; //导入方法依赖的package包/类
public void receiveByFolder(Folder folder, JavamailConfig javamailConfig)
throws MessagingException, IOException {
logger.info("receive : {}", folder);
if ((Folder.HOLDS_MESSAGES & folder.getType()) != 0) {
this.receiveMessageByFolder(folder, javamailConfig);
}
if ((Folder.HOLDS_FOLDERS & folder.getType()) != 0) {
for (Folder childFolder : folder.list()) {
this.receiveByFolder(childFolder, javamailConfig);
}
}
if (folder.isOpen()) {
// 关闭资源
folder.close(false);
}
}
示例2: clear
import javax.mail.Folder; //导入方法依赖的package包/类
private static void clear(Folder folder) throws MessagingException {
if(folder.exists() && (folder.getType() & Folder.HOLDS_MESSAGES) == Folder.HOLDS_MESSAGES) {
int totMessages = folder.getMessageCount();
System.out.println(totMessages + " messages from folder: " + folder.getFullName());
folder.open(Folder.READ_WRITE);
Message[] messages = folder.getMessages();
for (int i = 0; i < messages.length; i++) {
System.out.println("Deleting message: " + (i+1) + " of " + totMessages);
messages[i].setFlag(Flags.Flag.DELETED, true);
}
folder.close(true);
}
Folder[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
clear(childs[i]);
}
}
示例3: main
import javax.mail.Folder; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception {
String fileName = MailConstants.PROPS_FILE_NAME;
String protocol = null;
String host = null;
String user = null;
String password = null;
String root = null;
// If argc == 1, assume it's a Properties file.
if (argv.length == 1) {
fileName = argv[0];
FileProperties fp = new FileProperties(fileName);
fp.load();
protocol = fp.getProperty(MailConstants.RECV_PROTO);
host = fp.getProperty(MailConstants.RECV_HOST);
user = fp.getProperty(MailConstants.RECV_USER);
password = fp.getProperty(MailConstants.RECV_PASS);
root = fp.getProperty(MailConstants.RECV_ROOT);
}
// If not, assume listing all args in long form.
else if (argv.length == 5) {
protocol = argv[0];
host = argv[1];
user = argv[2];
password = argv[3];
root = argv[4];
}
// Otherwise give up.
else {
System.err.println(
"Usage: MailLister protocol host user pw root");
System.exit(0);
}
boolean recursive = false;
// Start with a JavaMail Session object
Session session = Session.getDefaultInstance(
System.getProperties(), null);
session.setDebug(false);
// Get a Store object for the given protocol
Store store = session.getStore(protocol);
if (password.equals("*")) {
final char[] passBytes =
System.console().readPassword("Password:", (Object[])null);
password = new String(passBytes);
}
store.connect(host, user, password);
// Get Folder object for root, and list it
// If root name = "", getDefaultFolder(), else getFolder(root)
Folder rf;
if (root.length() != 0) {
System.out.println("Getting folder " + root + ".");
rf = store.getFolder(root);
} else {
System.out.println("Getting default folder.");
rf = store.getDefaultFolder();
}
rf.open(Folder.READ_WRITE);
if (rf.getType() == Folder.HOLDS_FOLDERS) {
Folder[] fs = rf.list();
for (Folder f : fs) {
listFolder(f, "", recursive);
}
} else {
listFolder(rf, "", false);
}
}
示例4: listFolder
import javax.mail.Folder; //导入方法依赖的package包/类
static void listFolder(Folder folder, String tab, boolean recurse)
throws Exception {
folder.open(Folder.READ_WRITE);
System.out.println(tab + "Name: " + folder.getName() + '(' +
folder.getFullName() + ')');
if (!folder.isSubscribed())
System.out.println(tab + "Not Subscribed");
if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) {
if (folder.hasNewMessages())
System.out.println(tab + "Has New Messages");
else
System.out.println(tab + "No New Messages");
Message[] msgs = folder.getMessages();
for (Message m : msgs) {
Address from = m.getFrom()[0];
String fromAddress;
if (from instanceof InternetAddress)
fromAddress = ((InternetAddress)from).getAddress();
else
fromAddress = from.toString();
StringBuffer sb = new StringBuffer();
fromFmt.format(fromAddress, sb, null);
sb. append(" ");
subjFmt.format(m.getSubject(), sb, null);
System.out.println(sb.toString());
}
}
if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) {
System.out.println(tab + "Is Directory");
}
if (recurse) {
Folder[] fs = folder.list();
for (Folder f : fs) {
listFolder(f, tab + "", recurse);
}
}
}
示例5: getMessage
import javax.mail.Folder; //导入方法依赖的package包/类
public void getMessage( cfImapConnection imapConnection, String rootFolder, long messageID, String _attachURI, String _attachDIR ) throws cfmRunTimeException {
try{
Folder folderToList;
if ( rootFolder == null || rootFolder.length() == 0 )
folderToList = imapConnection.mailStore.getDefaultFolder();
else
folderToList = imapConnection.mailStore.getFolder(rootFolder);
if ( (folderToList.getType() & Folder.HOLDS_MESSAGES) != 0){
if ( !folderToList.isOpen() )
folderToList.open( Folder.READ_ONLY );
boolean bResult = false;
if ( folderToList instanceof UIDFolder )
bResult = extractMessage( ((UIDFolder)folderToList).getMessageByUID( messageID ), messageID, _attachURI, _attachDIR );
else
bResult = extractMessage( folderToList.getMessage( (int)messageID ), messageID, _attachURI, _attachDIR );
if ( !bResult ) imapConnection.setStatus( false, "Message does not exist" );
else imapConnection.setStatus( true, "" );
folderToList.close(false);
}
}catch(Exception E){
imapConnection.setStatus( false, E.getMessage() );
}
}
示例6: listFolder
import javax.mail.Folder; //导入方法依赖的package包/类
public cfQueryResultData listFolder( cfImapConnection imapConnection, String rootFolder) throws cfmRunTimeException {
cfQueryResultData query = new cfQueryResultData( new String[]{"fullname","name","totalmessages","unread","new"},"CFIMAP" );
try{
Folder folderToList;
if ( rootFolder == null || rootFolder.length() == 0 )
folderToList = imapConnection.mailStore.getDefaultFolder();
else
folderToList = imapConnection.mailStore.getFolder(rootFolder);
if ( (folderToList.getType() & Folder.HOLDS_FOLDERS) != 0){
Folder[] folderArray = folderToList.list();
query.addRow( folderArray.length );
for (int i = 0; i < folderArray.length; i++)
folderRow( query, i+1, folderArray[i] );
}
}catch(Exception E){}
return query;
}
示例7: listAllFolders
import javax.mail.Folder; //导入方法依赖的package包/类
public cfQueryResultData listAllFolders( cfImapConnection imapConnection) throws cfmRunTimeException {
cfQueryResultData query = new cfQueryResultData( new String[]{"fullname","name","totalmessages","unread","new"},"CFIMAP" );
try{
Folder folderToList;
folderToList = imapConnection.mailStore.getDefaultFolder();
if ( (folderToList.getType() & Folder.HOLDS_FOLDERS) != 0){
Folder[] folderArray = folderToList.list("*");
query.addRow( folderArray.length );
for (int i = 0; i < folderArray.length; i++)
folderRow( query, i+1, folderArray[i] );
}
}catch(Exception E){}
return query;
}
示例8: listFolderMessages
import javax.mail.Folder; //导入方法依赖的package包/类
public cfQueryResultData listFolderMessages( cfImapConnection imapConnection, String rootFolder, int startRow, int totalMessages, boolean reverseOrder ) {
cfQueryResultData query = new cfQueryResultData( new String[]{"subject","id","rxddate","sentdate","from","to","cc","bcc","size","lines","answered","deleted","draft","flagged","recent","seen"}, "CFIMAP" );
try{
Folder folderToList;
if ( rootFolder == null || rootFolder.length() == 0 )
folderToList = imapConnection.mailStore.getDefaultFolder();
else
folderToList = imapConnection.mailStore.getFolder(rootFolder);
if ( (folderToList.getType() & Folder.HOLDS_MESSAGES) != 0){
if ( !folderToList.isOpen() )
folderToList.open( Folder.READ_ONLY );
Message[] messageArray;
if ( startRow != -1 ){
int folderCount = folderToList.getMessageCount();
int start, end;
if ( !reverseOrder ){
start = startRow;
if ( folderCount < (startRow+totalMessages-1) ){
start = startRow;
end = folderCount;
}else{
end = startRow + totalMessages - 1;
}
}else{
end = folderCount - startRow + 1;
if ( folderCount < (startRow+totalMessages-1) ){
start = 1;
}else{
start = folderCount - startRow - totalMessages + 2;
}
}
messageArray = folderToList.getMessages( start, end );
imapConnection.setTotalMessages( folderCount );
}else{
messageArray = folderToList.getMessages();
imapConnection.setTotalMessages( messageArray.length );
}
// To improve performance, pre-fetch all of the message items
// used by the CFIMAP list action. This will retrieve all of the
// items for all of the messages with one single FETCH command.
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.FLAGS);
fp.add(FetchProfile.Item.CONTENT_INFO);
folderToList.fetch(messageArray, fp);
List<Map<String, cfData>> vectorMessages = new ArrayList<Map<String, cfData>>(messageArray.length);
if ( reverseOrder ){
int msgIndex = messageArray.length-1;
for (int i = 0; i < messageArray.length; i++)
vectorMessages.add( extractMessage( messageArray[msgIndex--] ) );
}else{
for (int i = 0; i < messageArray.length; i++)
vectorMessages.add( extractMessage( messageArray[i] ) );
}
folderToList.close(false);
query.populateQuery( vectorMessages );
}
}catch(Exception E){
cfEngine.log( E.getMessage() );
imapConnection.setStatus( false, E.getMessage() );
}
return query;
}