|  |  | @ -12,6 +12,7 @@ import org.stringtemplate.v4.ST; | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.mail.*; |  |  |  | import javax.mail.*; | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.mail.internet.AddressException; |  |  |  | import javax.mail.internet.AddressException; | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.mail.internet.InternetAddress; |  |  |  | import javax.mail.internet.InternetAddress; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import javax.xml.crypto.Data; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.io.*; |  |  |  | import java.io.*; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.sql.ResultSet; |  |  |  | import java.sql.ResultSet; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.sql.SQLException; |  |  |  | import java.sql.SQLException; | 
			
		
	
	
		
		
			
				
					|  |  | @ -27,14 +28,16 @@ import static de.srsoftware.widerhall.data.User.PERMISSION_ADMIN; | 
			
		
	
		
		
			
				
					
					|  |  |  |  * this class encapsulates a MailingList db object |  |  |  |  * this class encapsulates a MailingList db object | 
			
		
	
		
		
			
				
					
					|  |  |  |  */ |  |  |  |  */ | 
			
		
	
		
		
			
				
					
					|  |  |  | public class MailingList implements MessageHandler, ProblemListener { |  |  |  | public class MailingList implements MessageHandler, ProblemListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_FORWARD_FROM = "forward_from"; |  |  |  |     public static final String KEY_ARCHIVE = "archive"; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public static final String KEY_DELETE_MESSAGES = "delete_messages"; | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_FORWARD_ATTACHED = "forward_attached"; |  |  |  |     public static final String KEY_FORWARD_ATTACHED = "forward_attached"; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public static final String KEY_FORWARD_FROM = "forward_from"; | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_HIDE_RECEIVERS = "hide_receivers"; |  |  |  |     public static final String KEY_HIDE_RECEIVERS = "hide_receivers"; | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_REPLY_TO_LIST = "reply_to_list"; |  |  |  |     public static final String KEY_MODS_CAN_EDIT_MODS = "edit_mods"; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_OPEN_FOR_GUESTS = "open_for_guests"; |  |  |  |     public static final String KEY_OPEN_FOR_GUESTS = "open_for_guests"; | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_OPEN_FOR_SUBSCRIBERS = "open_for_subscribers"; |  |  |  |     public static final String KEY_OPEN_FOR_SUBSCRIBERS = "open_for_subscribers"; | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_ARCHIVE = "archive"; |  |  |  |     public static final String KEY_REPLY_TO_LIST = "reply_to_list"; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     public static final String KEY_MODS_CAN_EDIT_MODS = "edit_mods"; |  |  |  |     public static final String HOLD_TIME = "hold_time"; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     private static final Logger LOG = LoggerFactory.getLogger(MailingList.class); |  |  |  |     private static final Logger LOG = LoggerFactory.getLogger(MailingList.class); | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final String IMAP_HOST = "imap_host"; |  |  |  |     private static final String IMAP_HOST = "imap_host"; | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final String IMAP_PORT = "imap_port"; |  |  |  |     private static final String IMAP_PORT = "imap_port"; | 
			
		
	
	
		
		
			
				
					|  |  | @ -68,6 +71,7 @@ public class MailingList implements MessageHandler, ProblemListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |     private ImapClient imap; |  |  |  |     private ImapClient imap; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final HashMap<String,MailingList> cache = new HashMap<>(); |  |  |  |     private static final HashMap<String,MailingList> cache = new HashMap<>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private Integer holdTime = null; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     /** |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |      * create a new ML object |  |  |  |      * create a new ML object | 
			
		
	
	
		
		
			
				
					|  |  | @ -123,6 +127,10 @@ public class MailingList implements MessageHandler, ProblemListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, DEFAULT_STATE).save(); |  |  |  |         return new MailingList(email, name, imapHost, imapPort, imapUser, imapPass, inbox, smtpHost, smtpPort, smtpUser, smtpPass, DEFAULT_STATE).save(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public static void createHoldTimeColumn() throws SQLException { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Database.open().createColumn(TABLE_NAME,HOLD_TIME,INT); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     /** |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |      * create underlying db table |  |  |  |      * create underlying db table | 
			
		
	
		
		
			
				
					
					|  |  |  |      * @throws SQLException |  |  |  |      * @throws SQLException | 
			
		
	
	
		
		
			
				
					|  |  | @ -148,6 +156,20 @@ public class MailingList implements MessageHandler, ProblemListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |         Database.open().query(sql).compile().run(); |  |  |  |         Database.open().query(sql).compile().run(); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public void deleteMessages(boolean enable, String daysString) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             holdTime = enable ? Integer.parseInt(daysString) : null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             Database.open().update(TABLE_NAME).set(HOLD_TIME, holdTime).run(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } catch (SQLException throwables) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             LOG.warn("Failed to update {} setting!",HOLD_TIME); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private void dropOldMails() throws MessagingException { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (holdTime == null) return; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         imap.dropMailsOlderThan(holdTime); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public String email() { |  |  |  |     public String email() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return email; |  |  |  |         return email; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | @ -226,6 +248,10 @@ public class MailingList implements MessageHandler, ProblemListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return setFlag(STATE_HIDE_RECEIVERS,hide); |  |  |  |         return setFlag(STATE_HIDE_RECEIVERS,hide); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public Integer holdTime() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return holdTime; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     /** |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |      * test, whether the current ML is subscribable by a given user |  |  |  |      * test, whether the current ML is subscribable by a given user | 
			
		
	
		
		
			
				
					
					|  |  |  |      * @param user |  |  |  |      * @param user | 
			
		
	
	
		
		
			
				
					|  |  | @ -435,7 +461,7 @@ public class MailingList implements MessageHandler, ProblemListener { | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (SQLException e){ |  |  |  |         } catch (SQLException e){ | 
			
		
	
		
		
			
				
					
					|  |  |  |             LOG.warn("Failed to process message '{}'",subject,e); |  |  |  |             LOG.warn("Failed to process message '{}'",subject,e); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |         dropOldMails(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public MailingList openForGuests(boolean open) throws SQLException { |  |  |  |     public MailingList openForGuests(boolean open) throws SQLException { | 
			
		
	
	
		
		
			
				
					|  |  | 
 |