001 /* 002 * Copyright 2010 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package com.hs.mail.imap.schedule; 017 018 import java.util.Date; 019 020 import org.apache.commons.lang.time.DateUtils; 021 import org.apache.log4j.Logger; 022 import org.quartz.JobExecutionContext; 023 import org.quartz.JobExecutionException; 024 import org.springframework.scheduling.quartz.QuartzJobBean; 025 026 import com.hs.mail.container.config.Config; 027 import com.hs.mail.imap.mailbox.MailboxManager; 028 029 /** 030 * 031 * @author Won Chul Doh 032 * @since Sep 28, 2010 033 * 034 */ 035 public class DiskCleanupJob extends QuartzJobBean { 036 037 static Logger logger = Logger.getLogger(DiskCleanupJob.class); 038 039 private MailboxManager manager; 040 041 public void setMailboxManager(MailboxManager manager) { 042 this.manager = manager; 043 } 044 045 @Override 046 protected void executeInternal(JobExecutionContext context) 047 throws JobExecutionException { 048 if (logger.isDebugEnabled()) { 049 logger.debug("Starting disk cleanup job."); 050 } 051 String prop = Config.getProperty("stop_cron_after", "2h"); 052 Date stopAt = ScheduleUtils.getTimeAfter(prop, DateUtils.addHours( 053 new Date(), 2)); 054 if ((prop = Config.getProperty("expunge_after", null)) != null) { 055 new MessageExpunger(manager).expunge(prop, stopAt.getTime()); 056 } 057 if ((prop = Config.getProperty("compress_after", null)) != null) { 058 new MessageCompressor().compress(prop, stopAt.getTime()); 059 } 060 } 061 062 }