Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions FlowCrypt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
9F7E903926A1AD7A0021C07F /* KeyDetailsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F7E903826A1AD7A0021C07F /* KeyDetailsTests.swift */; };
9F82779823737E0900E19C07 /* MessageViewDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F82779723737E0900E19C07 /* MessageViewDecorator.swift */; };
9F82D352256D74FA0069A702 /* InboxViewContainerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F82D351256D74FA0069A702 /* InboxViewContainerController.swift */; };
9F8C160826C1379A000A460F /* SignInImapTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FDF364C235A1CCD00614596 /* SignInImapTest.swift */; };
9F92EE72236F165E009BE0D7 /* EncryptedStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F92EE71236F165E009BE0D7 /* EncryptedStorage.swift */; };
9F9361A52573CE260009912F /* MessageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F9361A42573CE260009912F /* MessageProvider.swift */; };
9F9362062573D0C80009912F /* Gmail+MessagesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F9362052573D0C80009912F /* Gmail+MessagesList.swift */; };
Expand Down Expand Up @@ -548,6 +549,8 @@
9F82779B23737E2A00E19C07 /* MessageSubjectNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSubjectNode.swift; sourceTree = "<group>"; };
9F82779D23737E3800E19C07 /* MessageTextSubjectNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageTextSubjectNode.swift; sourceTree = "<group>"; };
9F82D351256D74FA0069A702 /* InboxViewContainerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxViewContainerController.swift; sourceTree = "<group>"; };
9F8C160E26C137B9000A460F /* Gmail.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Gmail.xctestplan; sourceTree = "<group>"; };
9F8C161426C1382E000A460F /* Imap.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Imap.xctestplan; sourceTree = "<group>"; };
9F8D5E61236B04E300186E43 /* CellNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellNode.swift; sourceTree = "<group>"; };
9F92EE6F236F144C009BE0D7 /* TextFieldCellNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldCellNode.swift; sourceTree = "<group>"; };
9F92EE71236F165E009BE0D7 /* EncryptedStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptedStorage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -592,7 +595,7 @@
9FDF3639235A0B3B00614596 /* HeaderNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderNode.swift; sourceTree = "<group>"; };
9FDF3641235A1B0100614596 /* FlowCryptUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlowCryptUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9FDF3645235A1B0100614596 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9FDF364C235A1CCD00614596 /* SignInTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInTest.swift; sourceTree = "<group>"; };
9FDF364C235A1CCD00614596 /* SignInImapTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInImapTest.swift; sourceTree = "<group>"; };
9FDF364F235A1D3F00614596 /* UITestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITestHelper.swift; sourceTree = "<group>"; };
9FDF3651235A1EDE00614596 /* XCUIApplicationBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCUIApplicationBuilder.swift; sourceTree = "<group>"; };
9FDF3653235A218E00614596 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -706,7 +709,7 @@
D2F6D12E24324ACC00DB4065 /* SwitchCellNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchCellNode.swift; sourceTree = "<group>"; };
D2F6D1322433753100DB4065 /* IMAPSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IMAPSession.swift; sourceTree = "<group>"; };
D2F6D1342433753B00DB4065 /* SMTPSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SMTPSession.swift; sourceTree = "<group>"; };
D2F6D13D2434FF1400DB4065 /* providers.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = providers.json; sourceTree = "<group>"; };
D2F6D13D2434FF1400DB4065 /* providers.json */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = text.json; path = providers.json; sourceTree = "<group>"; };
D2F6D13F2435008500DB4065 /* SessionCredentialsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionCredentialsProvider.swift; sourceTree = "<group>"; };
D2F6D146243506DA00DB4065 /* MailSettingsCredentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailSettingsCredentials.swift; sourceTree = "<group>"; };
D2FC1C0524D82C9F003B949D /* ContactsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactsService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1404,7 +1407,9 @@
9FDF3642235A1B0100614596 /* FlowCryptUITests */ = {
isa = PBXGroup;
children = (
9FDF364C235A1CCD00614596 /* SignInTest.swift */,
9F8C160E26C137B9000A460F /* Gmail.xctestplan */,
9F8C161426C1382E000A460F /* Imap.xctestplan */,
9FDF364C235A1CCD00614596 /* SignInImapTest.swift */,
D2F18463244B0C63000CC5D1 /* SignInGoogleTest.swift */,
D216D05D242D32EA0083EDD6 /* TestCredentials.swift */,
9FDF3645235A1B0100614596 /* Info.plist */,
Expand Down Expand Up @@ -2481,6 +2486,7 @@
9F228BA923C67587005D2CB6 /* UserCredentials.swift in Sources */,
D2F18464244B0C63000CC5D1 /* SignInGoogleTest.swift in Sources */,
9F228BA623C673AD005D2CB6 /* Springboard.swift in Sources */,
9F8C160826C1379A000A460F /* SignInImapTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<TestPlans>
<TestPlanReference
reference = "container:FlowCryptUITests/Gmail.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
Expand Down
50 changes: 36 additions & 14 deletions FlowCrypt/Controllers/SetupImap/SetupImapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,22 @@ extension SetupImapViewController: ASTableDelegate, ASTableDataSource {
}

func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) -> ASCellNodeBlock { { [weak self] in
guard let self = self, let section = Section(indexPath: indexPath) else { return ASCellNode() }

switch section {
case .account(.title): return self.titleNode(for: indexPath)
case .imap(.title): return self.titleNode(for: indexPath)
case .smtp(.title): return self.titleNode(for: indexPath)
case .other(.title): return self.switchNode()
case .connect: return self.buttonNode()
default: return self.textFieldNode(for: indexPath)
}
guard let self = self, let section = Section(indexPath: indexPath) else { return ASCellNode() }

switch section {
case .account(.title):
return self.titleNode(for: indexPath)
case .imap(.title):
return self.titleNode(for: indexPath)
case .smtp(.title):
return self.titleNode(for: indexPath)
case .other(.title):
return self.switchNode()
case .connect:
return self.buttonNode()
default:
return self.textFieldNode(for: indexPath)
}
}
}
}
Expand Down Expand Up @@ -286,6 +292,20 @@ extension SetupImapViewController {
IndexPath(row: AccountPart.username.rawValue, section: Section.account(.username).section)
}

private func reloadImapSection() {
node.reloadSections(
IndexSet(integer: Section.imap(.port).section),
with: .none
)
}

private func reloadSmtpSection() {
node.reloadSections(
IndexSet(integer: Section.smtp(.port).section),
with: .none
)
}

private func reloadSessionCredentials() {
node.reloadSections(
IndexSet(integersIn: Section.imap(.port).section...Section.smtp(.port).section),
Expand Down Expand Up @@ -325,12 +345,12 @@ extension SetupImapViewController {
user.imap?.connectionType = connections[0].rawValue
case (.imap(.security), .didEndEditing):
updateUserImapCredentials()
reloadSessionCredentials()
reloadImapSection()
case (.smtp(.security), .didBeginEditing):
user.smtp?.connectionType = connections[0].rawValue
case (.smtp(.security), .didEndEditing):
updateUserSmtpCredentials()
reloadSessionCredentials()
reloadSmtpSection()
case (.other(.name), .didEndEditing(let name)):
user.smtp?.username = name ?? user.name
case (.other(.password), .didEndEditing(let password)):
Expand Down Expand Up @@ -393,7 +413,7 @@ extension SetupImapViewController {

switch settings {
case let .failure(.notFound(defaultPort)):
user.imap?.port = defaultPort
user.imap?.port = user.imap?.port ?? defaultPort
case let .success(imapSetting):
updateUser(imap: imapSetting)
}
Expand All @@ -408,7 +428,7 @@ extension SetupImapViewController {

switch settings {
case let .failure(.notFound(defaultPort)):
user.smtp?.port = defaultPort
user.smtp?.port = user.smtp?.port ?? defaultPort
case let .success(imapSetting):
updateUser(smtp: imapSetting)
}
Expand Down Expand Up @@ -463,6 +483,8 @@ extension SetupImapViewController {
// MARK: - Connect
extension SetupImapViewController {
private func connect() {
view.endEditing(true)

let result = checkCurrentUser()
switch result {
case .failure(.empty):
Expand Down
16 changes: 15 additions & 1 deletion FlowCrypt/Controllers/SetupImap/SetupImapViewDecorator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,45 +68,58 @@ struct SetupImapViewDecorator {
let placeholder: String?
var isSecure = false
var keyboardType: UIKeyboardType = .default
var accessibilityIdentifier: String?

switch section {
case let .account(part):
switch part {
case .email:
placeholder = "Email"
keyboardType = .emailAddress
accessibilityIdentifier = "Email"
case .password:
placeholder = "Password"
isSecure = true
accessibilityIdentifier = "Password"
case .username:
placeholder = "Username"
case .title:
placeholder = nil
}

// IMAP
case let .imap(part):
switch part {
case .port:
placeholder = "IMAP port"
keyboardType = .numberPad
accessibilityIdentifier = "IMAP port"
case .security:
placeholder = "Security type"
accessibilityIdentifier = "IMAP type"
case .server:
placeholder = "IMAP server"
case .title:
placeholder = nil
}

// SMTP
case let .smtp(part):
switch part {
case .port:
placeholder = "SMTP port"
keyboardType = .numberPad
accessibilityIdentifier = "SMTP port"
case .security:
placeholder = "Security type"
accessibilityIdentifier = "SMTP type"
case .server:
placeholder = "SMTP server"
case .title:
placeholder = nil
}

// OTHER
case let .other(part):
switch part {
case .name:
Expand All @@ -131,7 +144,8 @@ struct SetupImapViewDecorator {
darkStyle: .darkGray,
lightStyle: UIColor(white: 1, alpha: 1)
),
keyboardType: keyboardType
keyboardType: keyboardType,
accessibilityIdentifier: accessibilityIdentifier
)
}

Expand Down
2 changes: 1 addition & 1 deletion FlowCrypt/Core/Models/PassPhraseObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class PassPhraseObject: Object {
self.value = value
self.allFingerprints.append(objectsIn: fingerprints)
}

override class func primaryKey() -> String? {
"value"
}
Expand Down
40 changes: 24 additions & 16 deletions FlowCrypt/Functionality/Mail Provider/Imap/Imap+session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,21 @@ extension Imap {
logger.logInfo("Creating a new IMAP session")
let newImapSession = MCOIMAPSession(session: imap)
imapSess = newImapSession
logIMAPConnection(for: imapSess!)
.log()
}

if let smtp = smtpSession {
logger.logInfo("Creating a new SMTP session")
let newSmtpSession = MCOSMTPSession(session: smtp)
smtpSess = newSmtpSession
logSMTPConnection(for: smtpSess!)
}
}

private func logIMAPConnection(for session: MCOIMAPSession) {
session.connectionLogger = { [weak self] connectionID, type, data in
guard let data = data, let string = String(data: data, encoding: .utf8) else { return }
self?.logger.logInfo("connection IMAP :\(type):\(string)")
}
}

private func logSMTPConnection(for smtpSession: MCOSMTPSession) {
smtpSession.connectionLogger = { [weak self] connectionID, type, data in
guard let data = data, let string = String(data: data, encoding: .utf8) else { return }
self?.logger.logInfo("connection SMTP:\(type):\(string)")
.log()
}
}

func connectSmtp(session: SMTPSession) -> Promise<Void> {
Promise { resolve, reject in
MCOSMTPSession(session: session)
.log()
.loginOperation()?
.start { error in
guard let error = error else { resolve(()); return }
Expand All @@ -68,6 +55,7 @@ extension Imap {
func connectImap(session: IMAPSession) -> Promise<Void> {
Promise { resolve, reject in
MCOIMAPSession(session: session)
.log()
.connectOperation()?
.start { [weak self] error in
guard let error = error else { resolve(()); return }
Expand All @@ -91,3 +79,23 @@ extension Imap {
smtpSess = nil // smtp session has no disconnect method
}
}

extension MCOIMAPSession {
func log() -> Self {
connectionLogger = { connectionID, type, data in
guard let data = data, let string = String(data: data, encoding: .utf8) else { return }
Logger.nested("IMAP").logInfo("\(type):\(string)")
}
return self
}
}

extension MCOSMTPSession {
func log() -> Self {
connectionLogger = { connectionID, type, data in
guard let data = data, let string = String(data: data, encoding: .utf8) else { return }
Logger.nested("SMTP").logInfo("\(type):\(string)")
}
return self
}
}
Loading