Howto access Flags.Flag value in javax.mail?
이전 댓글 표시
Dear all,
I am stuck finding a solution for the following problem:
Problem description:
I want to download all unseen mails from a mailaccount using the JavaMail package in MATLAB. I am able to setup, connect and open the folder I want to get the mails from. For finding all messages that are unseen, I want to use the function IMAPFolder.search(SearchTerm term). For this SearchTerm, a Flags.Flag is required which is defined in a nested public static final class in javax.mail.Flags. The problem is now how to get the values of this class.
What I tried and what errors I get:
I already tried several ways to access fields in a nested java class, here is a list:
For the following link below, the first solution does not work for me because I am not able to change the Java library. Also the second solution does not work because it is a static class.
In the following solution https://www.mathworks.com/matlabcentral/answers/15711-how-do-i-access-a-java-inner-class-from-matlab it says:
SEEN = javaMethod('valueOf', 'javax.mail.Flags$Flag', 'SEEN')
And this is the error I get:
Error using javaMethod
No method valueOf exists in Java class javax.mail.Flags$Flag
I also found another question about this topic here:
My most recent code:
config = load('myconfig.mat');
props = java.util.Properties;
props.put('mail.imap.port', config.MAIL.port);
props.put('mail.imap.timeout', config.MAIL.imap_timeout);
props.put('mail.imaps.connectiontimeout', config.MAIL.imaps_connection_timeout);
session = javax.mail.Session.getInstance(props);
imapstore = session.getStore('imaps');
imapstore.connect( ...
config.MAIL.server, ...
config.MAIL.port, ...
config.MAIL.username, ...
config.MAIL.password ...
);
folder = imapstore.getFolder('Inbox');
folder.open(folder.READ_ONLY);
% everything works fine up to this point
search_flags = javax.mail.Flags;
flags_class = search_flags.getClass;
nested_classes = flags_class.getClasses;
flag_class = nested_classes(1);
% how do I access the static fields now?
Can someone help me? My Matlab version is R2016a.
EDIT1:
I also tried creating the FlagTerm using
cl = flags_class.getClassLoader;
rt = java.lang.Class.forName('javax.mail.Flags$Flag', false, cl);
search_flags.add(rt.getField('SEEN'));
as seen in http://de.mathworks.com/matlabcentral/newsreader/view_thread/125420 but it resulted in the following error:
No method 'add' with matching signature found for class 'javax.mail.Flags'.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Functions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!