@@ -881,23 +881,19 @@ public void sendMessage(MimeMessage mimeMessage) throws IOException, MessagingEx
881881 protected Folder internalGetFolder (String folderPath ) throws IOException {
882882 FolderId folderId = getFolderId (folderPath );
883883
884- GraphRequestBuilder httpRequestBuilder = null ;
884+ // base folder get https://graph.microsoft.com/v1.0/me/mailFolders/inbox
885+ GraphRequestBuilder httpRequestBuilder = new GraphRequestBuilder ()
886+ .setMethod ("GET" )
887+ .setMailbox (folderId .mailbox )
888+ .setObjectType ("mailFolders" )
889+ .setObjectId (folderId .id )
890+ .setExpandFields (FOLDER_PROPERTIES );
885891 if ("IPF.Appointment" .equals (folderId .folderClass )) {
886- httpRequestBuilder = new GraphRequestBuilder ()
887- .setMethod ("GET" )
888- .setMailbox (folderId .mailbox )
889- .setObjectType ("calendars" )
890- .setObjectId (folderId .id )
891- .setExpandFields (FOLDER_PROPERTIES );
892+ httpRequestBuilder .setObjectType ("calendars" );
893+ } else if ("IPF.Contact" .equals (folderId .folderClass )) {
894+ httpRequestBuilder .setObjectType ("contactFolders" );
892895 } else {
893-
894- // base folder get https://graph.microsoft.com/v1.0/me/mailFolders/inbox
895- httpRequestBuilder = new GraphRequestBuilder ()
896- .setMethod ("GET" )
897- .setMailbox (folderId .mailbox )
898- .setObjectType ("mailFolders" )
899- .setObjectId (folderId .id )
900- .setExpandFields (FOLDER_PROPERTIES );
896+ httpRequestBuilder .setObjectType ("mailFolders" );
901897 }
902898
903899 JSONObject jsonResponse = executeJsonRequest (httpRequestBuilder );
@@ -923,12 +919,12 @@ private Folder buildFolder(JSONObject jsonResponse) throws IOException {
923919 } else {
924920 // TODO: reevaluate folder name encoding over graph
925921 folder .displayName = EwsExchangeSession .encodeFolderName (jsonResponse .getString ("displayName" ));
926- folder .count = jsonResponse .getInt ("totalItemCount" );
927- folder .unreadCount = jsonResponse .getInt ("unreadItemCount" );
922+ folder .count = jsonResponse .optInt ("totalItemCount" );
923+ folder .unreadCount = jsonResponse .optInt ("unreadItemCount" );
928924 // fake recent value
929925 folder .recent = folder .unreadCount ;
930926 // hassubs computed from childFolderCount
931- folder .hasChildren = jsonResponse .getInt ("childFolderCount" ) > 0 ;
927+ folder .hasChildren = jsonResponse .optInt ("childFolderCount" ) > 0 ;
932928 }
933929
934930 // retrieve property values
@@ -1090,10 +1086,14 @@ protected FolderId getSubFolderByName(FolderId currentFolderId, String folderNam
10901086 .setExpandFields (FOLDER_PROPERTIES )
10911087 .setFilter ("name eq '" + StringUtil .davSearchEncode (EwsExchangeSession .decodeFolderName (folderName )) + "'" );
10921088 } else {
1089+ String objectType = "mailFolders" ;
1090+ if ("IPF.Contact" .equals (currentFolderId .folderClass )) {
1091+ objectType = "contactFolders" ;
1092+ }
10931093 httpRequestBuilder = new GraphRequestBuilder ()
10941094 .setMethod ("GET" )
10951095 .setMailbox (currentFolderId .mailbox )
1096- .setObjectType ("mailFolders" )
1096+ .setObjectType (objectType )
10971097 .setObjectId (currentFolderId .id )
10981098 .setChildType ("childFolders" )
10991099 .setExpandFields (FOLDER_PROPERTIES )
@@ -1154,11 +1154,15 @@ public int createFolder(String folderPath, String folderClass, Map<String, Strin
11541154 }
11551155
11561156 try {
1157+ String objectType = "mailFolders" ;
1158+ if ("IPF.Contact" .equals (folderClass )) {
1159+ objectType = "contactFolders" ;
1160+ }
11571161 executeJsonRequest (new GraphRequestBuilder ()
11581162 .setMethod ("POST" )
11591163 // TODO mailbox?
11601164 .setMailbox (parentFolderId .mailbox )
1161- .setObjectType ("mailFolders" )
1165+ .setObjectType (objectType )
11621166 .setObjectId (parentFolderId .id )
11631167 .setChildType ("childFolders" )
11641168 .setJsonBody (new JSONObject ().put ("displayName" , folderName )));
@@ -1192,10 +1196,14 @@ public void deleteFolder(String folderPath) throws IOException {
11921196 } else {
11931197 FolderId folderId = getFolderIdIfExists (folderPath );
11941198 if (folderId != null ) {
1199+ String objectType = "mailFolders" ;
1200+ if ("IPF.Contact" .equals (folderId .folderClass )) {
1201+ objectType = "contactFolders" ;
1202+ }
11951203 executeJsonRequest (new GraphRequestBuilder ()
11961204 .setMethod ("DELETE" )
11971205 .setMailbox (folderId .mailbox )
1198- .setObjectType ("mailFolders" )
1206+ .setObjectType (objectType )
11991207 .setObjectId (folderId .id ));
12001208 }
12011209 }
0 commit comments