@Test void deriveNewNameShouldNeverGenerateMoreThan86Characters() throws Exception { String longString = "mu1Eeseemu1Eeseemu1Eeseemu1Eeseemu1Eeseemu1Eeseemu1Eeseemu1Eeseemu1Eeseeseemu1Eesee"; assertThat(MailImpl.deriveNewName(longString).length()).isLessThan(86); }
@VisibleForTesting static String deriveNewName(String currentName) throws MessagingException { char separator = '!'; int loopThreshold = 7; int suffixLength = 9; int suffixMaxLength = loopThreshold * suffixLength; int nameMaxLength = suffixMaxLength + 13; detectPossibleLoop(currentName, loopThreshold, separator); String newName = currentName + generateRandomSuffix(suffixLength, separator); return stripFirstCharsIfNeeded(nameMaxLength, newName); }
MailImpl implements Disposable, Mail { @VisibleForTesting static String deriveNewName(String currentName) throws MessagingException { char separator = '!'; int loopThreshold = 7; int suffixLength = 9; int suffixMaxLength = loopThreshold * suffixLength; int nameMaxLength = suffixMaxLength + 13; detectPossibleLoop(currentName, loopThreshold, separator); String newName = currentName + generateRandomSuffix(suffixLength, separator); return stripFirstCharsIfNeeded(nameMaxLength, newName); } }
MailImpl implements Disposable, Mail { @VisibleForTesting static String deriveNewName(String currentName) throws MessagingException { char separator = '!'; int loopThreshold = 7; int suffixLength = 9; int suffixMaxLength = loopThreshold * suffixLength; int nameMaxLength = suffixMaxLength + 13; detectPossibleLoop(currentName, loopThreshold, separator); String newName = currentName + generateRandomSuffix(suffixLength, separator); return stripFirstCharsIfNeeded(nameMaxLength, newName); } private  MailImpl(String name,
                     String state,
                     Map<AttributeName, Attribute> attributes,
                     List<MailAddress> recipients,
                     PerRecipientHeaders perRecipientHeaders); }
MailImpl implements Disposable, Mail { @VisibleForTesting static String deriveNewName(String currentName) throws MessagingException { char separator = '!'; int loopThreshold = 7; int suffixLength = 9; int suffixMaxLength = loopThreshold * suffixLength; int nameMaxLength = suffixMaxLength + 13; detectPossibleLoop(currentName, loopThreshold, separator); String newName = currentName + generateRandomSuffix(suffixLength, separator); return stripFirstCharsIfNeeded(nameMaxLength, newName); } private  MailImpl(String name,
                     String state,
                     Map<AttributeName, Attribute> attributes,
                     List<MailAddress> recipients,
                     PerRecipientHeaders perRecipientHeaders); static MailImpl duplicate(Mail mail); static MailImpl fromMimeMessage(String name, MimeMessage mimeMessage); static RequireName builder(); @Override String getErrorMessage(); @Override MimeMessage getMessage(); @Override void setName(String name); @Override String getName(); @Override Collection<MailAddress> getRecipients(); @Override MailAddress getSender(); @Override String getState(); @Override String getRemoteHost(); @Override String getRemoteAddr(); @Override Date getLastUpdated(); @Override long getMessageSize(); @Override void setErrorMessage(String msg); @Override void setMessage(MimeMessage message); @Override void setRecipients(Collection<MailAddress> recipients); void setSender(MailAddress sender); @Override void setState(String state); void setRemoteHost(String remoteHost); void setRemoteAddr(String remoteAddr); @Override void setLastUpdated(Date lastUpdated); void writeMessageTo(OutputStream out); @Override void dispose(); Map<String, Object> getAttributesRaw(); void setAttributesRaw(Map<String, Object> attr); @Override Stream<Attribute> attributes(); @Override Serializable getAttribute(String key); @Override Optional<Attribute> getAttribute(AttributeName name); @Override Serializable setAttribute(String key, Serializable object); @Override Optional<Attribute> setAttribute(Attribute attribute); @Override Serializable removeAttribute(String key); @Override Optional<Attribute> removeAttribute(AttributeName attributeName); @Override void removeAllAttributes(); @Override Iterator<String> getAttributeNames(); @Override Stream<AttributeName> attributeNames(); @Override boolean hasAttributes(); static String getId(); @Override PerRecipientHeaders getPerRecipientSpecificHeaders(); @Override void addSpecificHeaderForRecipient(Header header, MailAddress recipient); void addAllSpecificHeaderForRecipient(PerRecipientHeaders perRecipientHeaders); @Override Mail duplicate(); }
MailImpl implements Disposable, Mail { @VisibleForTesting static String deriveNewName(String currentName) throws MessagingException { char separator = '!'; int loopThreshold = 7; int suffixLength = 9; int suffixMaxLength = loopThreshold * suffixLength; int nameMaxLength = suffixMaxLength + 13; detectPossibleLoop(currentName, loopThreshold, separator); String newName = currentName + generateRandomSuffix(suffixLength, separator); return stripFirstCharsIfNeeded(nameMaxLength, newName); } private  MailImpl(String name,
                     String state,
                     Map<AttributeName, Attribute> attributes,
                     List<MailAddress> recipients,
                     PerRecipientHeaders perRecipientHeaders); static MailImpl duplicate(Mail mail); static MailImpl fromMimeMessage(String name, MimeMessage mimeMessage); static RequireName builder(); @Override String getErrorMessage(); @Override MimeMessage getMessage(); @Override void setName(String name); @Override String getName(); @Override Collection<MailAddress> getRecipients(); @Override MailAddress getSender(); @Override String getState(); @Override String getRemoteHost(); @Override String getRemoteAddr(); @Override Date getLastUpdated(); @Override long getMessageSize(); @Override void setErrorMessage(String msg); @Override void setMessage(MimeMessage message); @Override void setRecipients(Collection<MailAddress> recipients); void setSender(MailAddress sender); @Override void setState(String state); void setRemoteHost(String remoteHost); void setRemoteAddr(String remoteAddr); @Override void setLastUpdated(Date lastUpdated); void writeMessageTo(OutputStream out); @Override void dispose(); Map<String, Object> getAttributesRaw(); void setAttributesRaw(Map<String, Object> attr); @Override Stream<Attribute> attributes(); @Override Serializable getAttribute(String key); @Override Optional<Attribute> getAttribute(AttributeName name); @Override Serializable setAttribute(String key, Serializable object); @Override Optional<Attribute> setAttribute(Attribute attribute); @Override Serializable removeAttribute(String key); @Override Optional<Attribute> removeAttribute(AttributeName attributeName); @Override void removeAllAttributes(); @Override Iterator<String> getAttributeNames(); @Override Stream<AttributeName> attributeNames(); @Override boolean hasAttributes(); static String getId(); @Override PerRecipientHeaders getPerRecipientSpecificHeaders(); @Override void addSpecificHeaderForRecipient(Header header, MailAddress recipient); void addAllSpecificHeaderForRecipient(PerRecipientHeaders perRecipientHeaders); @Override Mail duplicate(); static final long serialVersionUID; }