我正在使用Mailkit GetSubfolders方法向服务器发送此请求/响应
C: A00000005 LIST "" "INBOX.%" RETURN (SUBSCRIBED CHILDREN STATUS (UIDVALIDITY))
S: * LIST (\HasNoChildren \UnMarked) "." INBOX.kkkk
S: * STATUS INBOX.kkkk (UIDVALIDITY 1491227899)
S: * LIST (\HasChildren \UnMarked) "." INBOX.Archive
S: * LIST (\HasChildren \UnMarked) "." INBOX.spam
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Sent
S: * STATUS INBOX.Sent (UIDVALIDITY 1491227490)
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Junk
S: * STATUS INBOX.Junk (UIDVALIDITY 1491227488)
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Drafts
S: * STATUS INBOX.Drafts (UIDVALIDITY 1491227487)
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Trash
S: * STATUS INBOX.Trash (UIDVALIDITY 1491227603)
S: A00000005 OK List completed (0.001 + 0.000 secs).
但是我注意到Outlook和其他邮件客户端显示了我使用MailKit GetSubfolders获取的帐户的更多文件夹。特别是INBOX.INBOX.dfgdfg文件夹。我执行了LIST"" " INBOX *" (将%更改为*)我看到这次服务器返回丢失的文件夹(见下文)。我的问题是如何使用MailKit方法进入INBOX.INBOX.dfgdfg文件夹?
C: A00000005 LIST "" "INBOX.*" RETURN (SUBSCRIBED CHILDREN STATUS (UIDVALIDITY))
S: * LIST (\HasNoChildren \UnMarked) "." INBOX.kkkk
S: * STATUS INBOX.kkkk (UIDVALIDITY 1491227899)
S: * LIST (\HasChildren \UnMarked) "." INBOX.Archive
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Archive.000
S: * STATUS INBOX.Archive.000 (UIDVALIDITY 1491227889)
S: * LIST (\HasNoChildren \UnMarked) "." INBOX.Archive.aaaaa
S: * STATUS INBOX.Archive.aaaaa (UIDVALIDITY 1491227877)
S: * LIST (\HasChildren \UnMarked) "." INBOX.spam
S: * LIST (\HasNoChildren \UnMarked) "." INBOX.spam.666
S: * STATUS INBOX.spam.666 (UIDVALIDITY 1491227878)
S: * LIST (\HasNoChildren \UnMarked) "." INBOX.spam.nnhnhn
S: * STATUS INBOX.spam.nnhnhn (UIDVALIDITY 1491227870)
S: * LIST (\HasNoChildren \UnMarked) "." INBOX.spam.test
S: * STATUS INBOX.spam.test (UIDVALIDITY 1491227856)
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Sent
S: * STATUS INBOX.Sent (UIDVALIDITY 1491227490)
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Junk
S: * STATUS INBOX.Junk (UIDVALIDITY 1491227488)
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Drafts
S: * STATUS INBOX.Drafts (UIDVALIDITY 1491227487)
S: * LIST (\Subscribed \HasNoChildren \UnMarked) "." INBOX.Trash
S: * STATUS INBOX.Trash (UIDVALIDITY 1491227603)
S: * LIST (\HasNoChildren \UnMarked) "." INBOX.INBOX.dfgdfg
S: * STATUS INBOX.INBOX.dfgdfg (UIDVALIDITY 1491227900)
S: A00000005 OK List completed (0.001 + 0.000 secs).
答案 0 :(得分:0)
我能够回答我的问题。 ImapClient.GetFolders返回命名空间中的所有文件夹,包括缺少的INBOX.INBOX.dfgdfg
答案 1 :(得分:0)
如果您想要递归,则需要在package com.rexios.wealthprojection;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.ISODateTimeFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by adelory on 7/31/2017.
*/
public class ReadableRRule {
public static String getReadableRRule(String rrule) throws TextParseException {
return getReadableRRule(rrule, true);
}
public static String getReadableRRule(String rrule, boolean capitalize) throws TextParseException {
Strings.init(Locale.getDefault().getLanguage());
HashMap<String, String> attributes = new HashMap<>();
try {
String[] attrArray = rrule.replace("RRULE:", "").split("[=;]");
String key = "";
String value = "";
for (String s : attrArray) {
if (key.isEmpty()) {
key = s;
continue;
}
if (value.isEmpty()) {
value = s;
}
attributes.put(key, value);
key = "";
value = "";
}
String interval = "";
String freq = "";
String byDay = "";
String until = "";
String count = "";
for (Map.Entry<String, String> entry : attributes.entrySet()) {
if (entry.getKey().equals("FREQ")) {
freq = entry.getValue();
} else if (entry.getKey().equals("UNTIL")) {
until = DateTimeFormat.shortDate().print(ISODateTimeFormat.basicDateTimeNoMillis().parseLocalDate(entry.getValue()));
} else if (entry.getKey().equals("INTERVAL")) {
interval = entry.getValue();
} else if (entry.getKey().equals("COUNT")) {
count = entry.getValue();
} else if (entry.getKey().equals("BYDAY")) {
// TODO: Make this work for monthly stuff
byDay = entry.getValue();
int num = 0;
Matcher matcher = Pattern.compile(".?\\d+").matcher(byDay);
if (matcher.find()) {
String temp = matcher.group();
num = Integer.parseInt(temp);
byDay = byDay.replace(temp, "");
}
boolean abbreviate = true;
if (byDay.length() == byDay.replace(",", "").length()) abbreviate = false;
byDay = byDay.replace(",", ", ");
byDay = byDay.replace("MO", abbreviate ? getShortDayName(0) : getFullDayName(0));
byDay = byDay.replace("TU", abbreviate ? getShortDayName(1) : getFullDayName(1));
byDay = byDay.replace("WE", abbreviate ? getShortDayName(2) : getFullDayName(2));
byDay = byDay.replace("TH", abbreviate ? getShortDayName(3) : getFullDayName(3));
byDay = byDay.replace("FR", abbreviate ? getShortDayName(4) : getFullDayName(4));
byDay = byDay.replace("SA", abbreviate ? getShortDayName(5) : getFullDayName(5));
byDay = byDay.replace("SU", abbreviate ? getShortDayName(6) : getFullDayName(6));
if (num != 0) {
String numText = "";
switch (num) {
case -1:
numText = Strings.last;
break;
case 1:
numText = Strings.first;
break;
case 2:
numText = Strings.second;
break;
case 3:
numText = Strings.third;
break;
case 4:
numText = Strings.fourth;
break;
}
byDay = "(" + Strings.on + " " + Strings.every + " " + numText + " " + byDay + ")";
} else {
byDay = Strings.on + " " + byDay;
}
}
}
if ((interval.isEmpty() || interval.equals("1")) && byDay.length() - byDay.replace(",", "").length() == 6) {
freq = "DAILY";
byDay = "";
}
String readableRRule = "";
switch (freq) {
case "DAILY":
if (interval.isEmpty() || interval.equals("1")) {
readableRRule += capitalize ? capitalize(Strings.daily) : Strings.daily;
} else {
readableRRule += capitalize ? capitalize(Strings.every) : Strings.every;
readableRRule += " " + interval + " " + Strings.days;
}
break;
case "WEEKLY":
if (interval.isEmpty() || interval.equals("1")) {
readableRRule += capitalize ? capitalize(Strings.weekly) : Strings.weekly;
} else {
readableRRule += capitalize ? capitalize(Strings.every) : Strings.every;
readableRRule += " " + interval + " " + Strings.weeks;
}
break;
case "MONTHLY":
if (interval.isEmpty() || interval.equals("1")) {
readableRRule += capitalize ? capitalize(Strings.monthly) : Strings.monthly;
} else {
readableRRule += capitalize ? capitalize(Strings.every) : Strings.every;
readableRRule += " " + interval + " " + Strings.months;
}
break;
case "YEARLY":
if (interval.isEmpty() || interval.equals("1")) {
readableRRule += capitalize ? capitalize(Strings.yearly) : Strings.yearly;
} else {
readableRRule += capitalize ? capitalize(Strings.every) : Strings.every;
readableRRule += " " + interval + " " + Strings.years;
}
break;
}
if (!byDay.isEmpty()) {
readableRRule += " " + byDay;
}
if (!until.isEmpty()) {
readableRRule += "; " + Strings.until + " " + until;
}
if (!count.isEmpty()) {
if (count.equals("1")) {
readableRRule += "; " + Strings.four + " " + Strings.one + " " + Strings.time;
} else {
readableRRule += "; " + Strings.four + " " + count + " " + Strings.times;
}
}
return readableRRule;
} catch (Exception e) {
e.printStackTrace();
throw new TextParseException();
}
}
// Get day of week Monday-Sunday (0-6)
private static String getFullDayName(int day) {
Calendar c = Calendar.getInstance();
c.set(2011, 7, 1, 0, 0, 0);
c.add(Calendar.DAY_OF_MONTH, day);
return String.format("%tA", c);
}
private static String getShortDayName(int day) {
Calendar c = Calendar.getInstance();
c.set(2011, 7, 1, 0, 0, 0);
c.add(Calendar.DAY_OF_MONTH, day);
return String.format("%ta", c);
}
private static String capitalize(String s) {
return s.substring(0, 1).toUpperCase() + s.substring(1);
}
private static class Strings {
static String daily = "daily";
static String weekly = "weekly";
static String monthly = "monthly";
static String yearly = "yearly";
static String days = "days";
static String weeks = "weeks";
static String months = "months";
static String years = "years";
static String every = "every";
static String on = "on";
static String until = "until";
static String four = "for"; // "for" is a reserved word
static String times = "times";
static String time = "time";
static String one = "one";
static String first = "first";
static String second = "second";
static String third = "third";
static String fourth = "fourth";
static String last = "last";
static void init(String language) {
// TODO: Support different locales
if (language.equals("es")) {
daily = "diariamente";
weekly = "semanal";
monthly = "mensual";
yearly = "anual";
days = "días";
weeks = "semanas";
months = "meses";
years = "años";
every = "cada";
on = "en";
until = "hasta";
four = "para";
times = "veces";
time = "vez";
one = "una";
first = "primero";
second = "segundo";
third = "tercero";
fourth = "cuarto";
last = "último";
}
}
}
public static class TextParseException extends Exception {
TextParseException() {
super();
}
TextParseException(String message) {
super(message);
}
}
}
返回的每个文件夹上调用GetSubfolders()
。
使用GetSubfolders()
的问题在于某些IMAP服务器( cough UW.IMAPd cough ),如果用户有符号链接,服务器响应将永远不会结束,因为它没有正确检测到符号链接递归。