@Override
public Quota getStorageQuota(MailboxSession session) throws MailboxException {
long max = getMaxStorage(session);
if (max != Quota.UNLIMITED || calculateWhenUnlimited) {
MessageMapper mapper = factory.getMessageMapper(session);
String id = session.getUser().getUserName();
AtomicLong size = sizes.get(id);
if (size == null) {
final AtomicLong mSizes = new AtomicLong(0);
List<Mailbox> mailboxes = factory.getMailboxMapper(session).findMailboxWithPathLike(new MailboxPath(session.getPersonalSpace(), id, "%"));
for (int i = 0; i < mailboxes.size(); i++) {
long messageSizes = 0;
Iterator<Message> messages = mapper.findInMailbox(mailboxes.get(i), MessageRange.all(), FetchType.Metadata, -1);
while(messages.hasNext()) {
messageSizes += messages.next().getFullContentOctets();
}
mSizes.set(mSizes.get() + messageSizes);