@@ -72,6 +72,27 @@ public class GraphExchangeSession extends ExchangeSession {
7272 */
7373 protected class Folder extends ExchangeSession .Folder {
7474 public FolderId folderId ;
75+ protected String specialFlag = "" ;
76+
77+ protected void setSpecialFlag (String specialFlag ) {
78+ this .specialFlag = "\\ " +specialFlag +" " ;
79+ }
80+
81+ /**
82+ * Get IMAP folder flags.
83+ *
84+ * @return folder flags in IMAP format
85+ */
86+ @ Override
87+ public String getFlags () {
88+ if (noInferiors ) {
89+ return specialFlag + "\\ NoInferiors" ;
90+ } else if (hasChildren ) {
91+ return specialFlag + "\\ HasChildren" ;
92+ } else {
93+ return specialFlag + "\\ HasNoChildren" ;
94+ }
95+ }
7596 }
7697
7798 // special folders https://learn.microsoft.com/en-us/graph/api/resources/mailfolder
@@ -85,6 +106,17 @@ public enum WellKnownFolderName {
85106 searchfolders
86107 }
87108
109+ // https://www.rfc-editor.org/rfc/rfc6154.html map well known names to special flags
110+ protected static HashMap <String , String > wellKnownFolderMap = new HashMap <>();
111+ static {
112+ wellKnownFolderMap .put (WellKnownFolderName .inbox .name (), ExchangeSession .INBOX );
113+ wellKnownFolderMap .put (WellKnownFolderName .archive .name (), ExchangeSession .ARCHIVE );
114+ wellKnownFolderMap .put (WellKnownFolderName .drafts .name (), ExchangeSession .DRAFTS );
115+ wellKnownFolderMap .put (WellKnownFolderName .junkemail .name (), ExchangeSession .JUNK );
116+ wellKnownFolderMap .put (WellKnownFolderName .sentitems .name (), ExchangeSession .SENT );
117+ wellKnownFolderMap .put (WellKnownFolderName .deleteditems .name (), ExchangeSession .TRASH );
118+ }
119+
88120 protected static final HashSet <FieldURI > IMAP_MESSAGE_ATTRIBUTES = new HashSet <>();
89121
90122 static {
@@ -730,19 +762,32 @@ public void appendTo(StringBuilder buffer) {
730762 }
731763 }
732764
765+ static class NotCondition extends ExchangeSession .NotCondition {
766+
767+ protected NotCondition (Condition condition ) {
768+ super (condition );
769+ }
770+
771+ @ Override
772+ public void appendTo (StringBuilder buffer ) {
773+ buffer .append ("not " );
774+ condition .appendTo (buffer );
775+ }
776+ }
777+
733778 @ Override
734779 public MultiCondition and (Condition ... condition ) {
735780 return new MultiCondition (Operator .And , condition );
736781 }
737782
738783 @ Override
739784 public MultiCondition or (Condition ... condition ) {
740- return null ;
785+ return new MultiCondition ( Operator . Or , condition ) ;
741786 }
742787
743788 @ Override
744789 public Condition not (Condition condition ) {
745- return null ;
790+ return new NotCondition ( condition ) ;
746791 }
747792
748793 @ Override
@@ -917,8 +962,18 @@ private Folder buildFolder(JSONObject jsonResponse) throws IOException {
917962 // calendar
918963 folder .displayName = EwsExchangeSession .encodeFolderName (jsonResponse .optString ("name" ));
919964 } else {
920- // TODO: reevaluate folder name encoding over graph
921- folder .displayName = EwsExchangeSession .encodeFolderName (jsonResponse .getString ("displayName" ));
965+ String wellKnownName = wellKnownFolderMap .get (jsonResponse .optString ("wellKnownName" ));
966+ if (ExchangeSession .INBOX .equals (wellKnownName )) {
967+ folder .displayName = wellKnownName ;
968+ } else {
969+ if (wellKnownName != null ) {
970+ folder .setSpecialFlag (wellKnownName );
971+ }
972+
973+ // TODO: reevaluate folder name encoding over graph
974+ folder .displayName = EwsExchangeSession .encodeFolderName (jsonResponse .getString ("displayName" ));
975+ }
976+
922977 folder .count = jsonResponse .optInt ("totalItemCount" );
923978 folder .unreadCount = jsonResponse .optInt ("unreadItemCount" );
924979 // fake recent value
@@ -1077,7 +1132,7 @@ private FolderId getWellKnownFolderId(String mailbox, WellKnownFolderName wellKn
10771132 */
10781133 protected FolderId getSubFolderByName (FolderId currentFolderId , String folderName ) throws IOException {
10791134 // TODO rename davSearchEncode
1080- GraphRequestBuilder httpRequestBuilder = null ;
1135+ GraphRequestBuilder httpRequestBuilder ;
10811136 if ("IPF.Appointment" .equals (currentFolderId .folderClass )) {
10821137 httpRequestBuilder = new GraphRequestBuilder ()
10831138 .setMethod ("GET" )
0 commit comments