Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Local Extension Support With Refactoring and Tests #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AkshayRajMaurya
Copy link

@AkshayRajMaurya AkshayRajMaurya commented Jan 16, 2023

  • Local Extension Support
  • Test For Local Extension Method
  • Refactored to make sendAs8BitMime as default and sevenBit when supported
  • Refactored Mail Command method conditions to use SMTPUTF8 and 8BITMIME conditionally depending on support

Detailed Description Of Changes :

src/main/java/com/hubspot/smtp/client/SmtpSession.java :

Line : 102 : I have my doubts over making this localExtensionsList Global and whether it should be kept as a volatile variable or not. This global variable is introduced to keep changes at bare minimum so that we don't have to pass it down to mail method. Comments are welcome for edits

Lines : 243-254 : General acceptor send method with one additional param for localExtensionsList : List<String>
here we set the earlier declared global variable.

Lines : 309-327 : sendInternal() method has been refactored to make it a bit simpler . I checked the flow and found the only difference in the sendAs7Bit vs sendAs8BitMime to be finally in the mailCommand vs mailCommandWith8BitMime. Rest remains the same. So I merged both the methods mailCommand and mailCommandWith8BitMime to one as mailCommand which reduced the two intermediate methods sendAs8BitMime and sendAs7Bit to one common method calling mailCommand. So now in case we are sending 7 bit / 8 bit appropriate extensions can be handled by mail command method based on checks used earlier and we just need to encode the content if required.

7/8bit checks in sendInternal Method () : Assume content to be 8 Bit . If ehlo Response does not support 8 bit then enforce 7 bit conversion. else if it supports then send it through and 8BitMime extension will be introduced by mailCommand method.
Rest all contents are 7 bit and can be handled by default way and we wont introduce 8BitMime extension.
NOTE : this removed content.get8bitCharacterProportion() == 0 too as we assume rest all are 7 bit except when we send 8 bit content.

Lines : 386-390 : removal of the two intermediate methods : sendAs7Bit and sendAs8BitMime to form a common method sendMessage

Lines : 415-427 : Reduced mailCommand and mailCommandWith8BitMime to one mailCommand method. The check being done to determine 8Bit i.e ehloResponse.isSupported(Extension.EIGHT_BIT_MIME) has been moved here to check whether we need extension BODY=8BITMIME or not. Rest SMTPUTF8 checks remain the same i.e apply SMTPUTF8 iff SMTPUTF8 is supported by ehlo response and all chars in from and recipients are not all ascii ( implies that there is one or more non ascii character anywhere) using condition ehloResponse.isSupported(Extension.SMTPUTF8) && !(isAllAscii(from) && isAllAscii(recipients))

src/test/java/com/hubspot/smtp/IntegrationTest.java

Lines : 368-402 : Standard test to see if everything is working as intended. Introduced new test method : itCanSendAnEmailWithLocalExtensions()
Added dummy extensions in localExtensionsList and sent via our new public send method which supports local extensions.
assert if everything works fine.
Had to disable chunking extension as it was not working for me with chunking enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant