Browse code

BM-13775 Fix: mbox record delete npp

David Phan authored on 08/01/2019 08:59:04
Showing 2 changed files
... ...
@@ -76,6 +76,11 @@ public abstract class AbstractByContainerReplicatedMailboxesServiceFactory<T>
76 76
 		String ownerUid = matched.group(2);
77 77
 		IMailboxes mboxApi = context.su().provider().instance(IMailboxes.class, domain);
78 78
 		ItemValue<Mailbox> mailbox = mboxApi.getComplete(ownerUid);
79
+
80
+		if (mailbox == null) {
81
+			throw new ServerFault("Mailbox not found '" + ownerUid + "'");
82
+		}
83
+
79 84
 		CyrusPartition cp = CyrusPartition.forServerAndDomain(mailbox.value.dataLocation, domain);
80 85
 		MailboxReplicaRootDescriptor rootDesc = MailboxReplicaRootDescriptor.create(ns, mailbox.value.name);
81 86
 
... ...
@@ -141,9 +141,14 @@ public class DbMailboxRecordsService extends BaseMailboxRecordsService implement
141 141
 	private ItemValue<MailboxFolder> getFolder() {
142 142
 
143 143
 		if (!mboxFolder.isPresent()) {
144
-			IDbByContainerReplicatedMailboxes foldersApi = context.provider()
145
-					.instance(IDbByContainerReplicatedMailboxes.class, recordsLocation.subtreeContainer);
146
-			mboxFolder = Optional.of(foldersApi.getComplete(mailboxUniqueId));
144
+			try {
145
+				IDbByContainerReplicatedMailboxes foldersApi = context.provider()
146
+						.instance(IDbByContainerReplicatedMailboxes.class, recordsLocation.subtreeContainer);
147
+				mboxFolder = Optional.of(foldersApi.getComplete(mailboxUniqueId));
148
+			} catch (ServerFault sf) {
149
+				logger.error("Fail to fetch folder {}", mailboxUniqueId, sf);
150
+				return null;
151
+			}
147 152
 		}
148 153
 
149 154
 		return mboxFolder.get();
... ...
@@ -391,6 +396,9 @@ public class DbMailboxRecordsService extends BaseMailboxRecordsService implement
391 396
 		ItemValue<Mailbox> box = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
392 397
 				.instance(IMailboxes.class, container.domainUid).getComplete(container.owner);
393 398
 		ItemValue<MailboxFolder> folder = getFolder();
399
+		if (folder == null) {
400
+			return;
401
+		}
394 402
 		indexService.expunge(null, box, folder, set);
395 403
 	}
396 404
 
... ...
@@ -401,12 +409,13 @@ public class DbMailboxRecordsService extends BaseMailboxRecordsService implement
401 409
 
402 410
 	@Override
403 411
 	public void prepareContainerDelete() {
404
-		ItemValue<Mailbox> box = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
405
-				.instance(IMailboxes.class, container.domainUid).getComplete(container.owner);
406 412
 		ItemValue<MailboxFolder> folder = getFolder();
407
-		indexService.deleteBox(null, box, folder.uid);
408
-
409
-		storeService.prepareContainerDelete();
413
+		if (folder != null) {
414
+			ItemValue<Mailbox> box = ServerSideServiceProvider.getProvider(SecurityContext.SYSTEM)
415
+					.instance(IMailboxes.class, container.domainUid).getComplete(container.owner);
416
+			indexService.deleteBox(null, box, folder.uid);
417
+			storeService.prepareContainerDelete();
418
+		}
410 419
 	}
411 420
 
412 421
 	@Override