我目前正在尝试使用JavaMail从IMAP服务器(Gmail和其他人)获取电子邮件.基本上,我的代码工作:我确实可以得到标题,正文内容等.我的问题如下:当处理IMAP服务器(没有SSL)时,处理消息基本上需要1-2ms.当我使用IMAPS服务器(因此使用SSL,例如Gmail)时,我的消息达到250米左右.我只测量处理消息的时间(不考虑连接,握手等).
我知道,因为这是SSL,所以数据是加密的.但是,解密的时间不应该那么重要,不是吗?
我已经尝试设置更高的ServerCacheSize值,更高的connectionpoolsize,但我的想法很严重.谁有人遇到这个问题?有人可能希望解决它吗?
我担心JavaMail API每次从IMAPS服务器获取邮件时都会使用不同的连接(涉及握手的开销......).如果是这样,有没有办法覆盖这种行为?
这是从Main()类调用的代码(虽然非常标准):
public static int connectTest(String SSL, String user, String pwd, String host) throws IOException,
ProtocolException,
GeneralSecurityException {
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", SSL);
props.setProperty("mail.imaps.ssl.trust", host);
props.setProperty("mail.imaps.connectionpoolsize", "10");
try {
Session session = Session.getDefaultInstance(props, null);
// session.setDebug(true);
Store store = session.getStore(SSL);
store.connect(host, user, pwd);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
int numMess = inbox.getMessageCount();
Message[] messages = inbox.getMessages();
for (Message m : messages) {
m.getAllHeaders();
m.getContent();
}
inbox.close(false);
store.close();
return numMess;
} catch (MessagingException e) {
e.printStackTrace(); …
Run Code Online (Sandbox Code Playgroud) 我正在使用chrono crate在 Rust 中解析日期和时间。日期和时间来自网站,其中日期和时间来自页面的不同部分。
日期以格式显示%d/%m/%Y
(例如:27/08/2018)。时间仅显示小时(例如:12、10、21 等)
我想将这些日期时间存储为 UTC,以便我可以以“时区不可知”的方式计算从现在到给定日期时间的剩余时间。我知道这些日期时间来自哪个时区(巴黎时间)。
我NaiveDate
从日期输入创建了一个(这是一项正在进行的工作,所以还没有错误处理):
let naive_date = NaiveDate::parse_from_str(date, "%d/%m/%Y").unwrap()
Run Code Online (Sandbox Code Playgroud)
从那时起DateTime
,考虑到我有一个带小时的字符串,获得 UTC 的最佳方法是什么?
我迷失在各种TimeZone
/Offset
特征中,不知道是否应该使用Local
, 或FixedOffset
然后转换为Utc
.
我在一个String
字符上使用了一个迭代器:
pub fn is_yelling(message: &str) -> bool {
let letters = message.chars().filter(|c| c.is_alphabetic());
message.chars().any(|c| c.is_alphabetic()) && letters.all(|c| c.is_uppercase())
}
Run Code Online (Sandbox Code Playgroud)
这会引发编译错误:
error[E0596]: cannot borrow immutable local variable `letters` as mutable
--> src/main.rs:3:51
|
2 | let letters = message.chars().filter(|c| c.is_alphabetic());
| ------- consider changing this to `mut letters`
3 | message.chars().any(|c| c.is_alphabetic()) && letters.all(|c| c.is_uppercase())
| ^^^^^^^ cannot borrow mutably
Run Code Online (Sandbox Code Playgroud)
当我变得letters
可变时,一切都顺利进行.
我不明白为什么这个必要.该all
方法不应该改变迭代器.喜欢map
或者filter
,取self
而不是mut self
作为论据.
我的参考map
/ …