Refactor++
authorHern?ni Marques <hernani@pep-project.org>
Tue, 25 Oct 2016 00:48:01 +0200
changeset 86585266cc78f4f
parent 864 4ce7ebb693bb
child 866 64469bc6c9a2
Refactor++
pEpForiOS.xcodeproj/project.pbxproj
pEpForiOS/Background/AppendSingleMessageOperation.swift
pEpForiOS/Background/CheckAndCreateFolderOfTypeOperation.swift
pEpForiOS/Background/FetchFoldersOperation.swift
pEpForiOS/Background/GrandOperator.swift
pEpForiOS/Background/PrefetchEmailsOperation.swift
pEpForiOS/Models/CdModel.swift
pEpForiOS/Network/EmailConnectInfo.swift
     1.1 --- a/pEpForiOS.xcodeproj/project.pbxproj	Mon Oct 24 23:57:03 2016 +0200
     1.2 +++ b/pEpForiOS.xcodeproj/project.pbxproj	Tue Oct 25 00:48:01 2016 +0200
     1.3 @@ -136,8 +136,6 @@
     1.4  		5D039A9C1D0EE7F900AD59EC /* PEPUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D039A9B1D0EE7F900AD59EC /* PEPUtil.swift */; };
     1.5  		5D039AA21D0EEA3700AD59EC /* DecryptMailOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D039AA11D0EEA3700AD59EC /* DecryptMailOperation.swift */; };
     1.6  		5D181C611DABE22C00379D99 /* NetworkBackgroundServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D181C601DABE22C00379D99 /* NetworkBackgroundServiceTests.swift */; };
     1.7 -		5D73EAC31DBEB11E00203AD0 /* ImapConnectInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D73EAC21DBEB11E00203AD0 /* ImapConnectInfo.swift */; };
     1.8 -		5D73EAC51DBEB13000203AD0 /* SmtpConnectInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D73EAC41DBEB13000203AD0 /* SmtpConnectInfo.swift */; };
     1.9  		5DF003981DBE430E00F11C04 /* ConnectInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DF003911DBE430E00F11C04 /* ConnectInfo.swift */; };
    1.10  		5DF003991DBE430E00F11C04 /* EmailConnectInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DF003921DBE430E00F11C04 /* EmailConnectInfo.swift */; };
    1.11  		5DF0039A1DBE430E00F11C04 /* EmailService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DF003931DBE430E00F11C04 /* EmailService.swift */; };
    1.12 @@ -393,8 +391,6 @@
    1.13  		5D039A9B1D0EE7F900AD59EC /* PEPUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PEPUtil.swift; sourceTree = "<group>"; };
    1.14  		5D039AA11D0EEA3700AD59EC /* DecryptMailOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DecryptMailOperation.swift; sourceTree = "<group>"; };
    1.15  		5D181C601DABE22C00379D99 /* NetworkBackgroundServiceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkBackgroundServiceTests.swift; sourceTree = "<group>"; };
    1.16 -		5D73EAC21DBEB11E00203AD0 /* ImapConnectInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImapConnectInfo.swift; path = pEpForiOS/Network/ImapConnectInfo.swift; sourceTree = SOURCE_ROOT; };
    1.17 -		5D73EAC41DBEB13000203AD0 /* SmtpConnectInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SmtpConnectInfo.swift; path = pEpForiOS/Network/SmtpConnectInfo.swift; sourceTree = SOURCE_ROOT; };
    1.18  		5DF003911DBE430E00F11C04 /* ConnectInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConnectInfo.swift; path = pEpForiOS/Network/ConnectInfo.swift; sourceTree = SOURCE_ROOT; };
    1.19  		5DF003921DBE430E00F11C04 /* EmailConnectInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EmailConnectInfo.swift; path = pEpForiOS/Network/EmailConnectInfo.swift; sourceTree = SOURCE_ROOT; };
    1.20  		5DF003931DBE430E00F11C04 /* EmailService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EmailService.swift; path = pEpForiOS/Network/EmailService.swift; sourceTree = SOURCE_ROOT; };
    1.21 @@ -685,8 +681,6 @@
    1.22  			isa = PBXGroup;
    1.23  			children = (
    1.24  				5DF003911DBE430E00F11C04 /* ConnectInfo.swift */,
    1.25 -				5D73EAC21DBEB11E00203AD0 /* ImapConnectInfo.swift */,
    1.26 -				5D73EAC41DBEB13000203AD0 /* SmtpConnectInfo.swift */,
    1.27  				5DF003921DBE430E00F11C04 /* EmailConnectInfo.swift */,
    1.28  				5DF003931DBE430E00F11C04 /* EmailService.swift */,
    1.29  				5DF003941DBE430E00F11C04 /* ImapService.swift */,
    1.30 @@ -1109,7 +1103,6 @@
    1.31  				43E42FF71D7096E400164CB1 /* DeleteMessageOperation.swift in Sources */,
    1.32  				431144AC1CC0CCE30007639D /* GrandOperator.swift in Sources */,
    1.33  				434F84451CEB018A0055B7A9 /* NSData+Extensions.swift in Sources */,
    1.34 -				5D73EAC51DBEB13000203AD0 /* SmtpConnectInfo.swift in Sources */,
    1.35  				43980EF81CBD402400A7FC3C /* CoreDataUtil.swift in Sources */,
    1.36  				4305AC7C1DA3FE9A00273D16 /* CdContact.swift in Sources */,
    1.37  				A1B50A841CD26FF100B1A997 /* Constants.swift in Sources */,
    1.38 @@ -1141,7 +1134,6 @@
    1.39  				43463AAE1D8AA54800F3A673 /* CheckAndCreateFolderOfTypeOperation.swift in Sources */,
    1.40  				4340F5F91D363BE6006A5C82 /* ContactTableViewCell.swift in Sources */,
    1.41  				43980EFA1CBD415700A7FC3C /* AppConfig.swift in Sources */,
    1.42 -				5D73EAC31DBEB11E00203AD0 /* ImapConnectInfo.swift in Sources */,
    1.43  				A1014DA71D1173CD00C472A8 /* UIHelper.swift in Sources */,
    1.44  				43001F7A1D91860A00306BF0 /* FetchTableViewController.swift in Sources */,
    1.45  				43E58ED11CBFA943008AA7A7 /* KeyChain.swift in Sources */,
     2.1 --- a/pEpForiOS/Background/AppendSingleMessageOperation.swift	Mon Oct 24 23:57:03 2016 +0200
     2.2 +++ b/pEpForiOS/Background/AppendSingleMessageOperation.swift	Tue Oct 25 00:48:01 2016 +0200
     2.3 @@ -21,7 +21,7 @@
     2.4  
     2.5      let accountID: NSManagedObjectID
     2.6  
     2.7 -    let connectInfo: ImapSmtpConnectInfo
     2.8 +    let connectInfo: EmailConnectInfo
     2.9  
    2.10      let connectionManager: ConnectionManager
    2.11  
     3.1 --- a/pEpForiOS/Background/CheckAndCreateFolderOfTypeOperation.swift	Mon Oct 24 23:57:03 2016 +0200
     3.2 +++ b/pEpForiOS/Background/CheckAndCreateFolderOfTypeOperation.swift	Tue Oct 25 00:48:01 2016 +0200
     3.3 @@ -19,7 +19,7 @@
     3.4      let comp = "CheckAndCreateFolderOfTypeOperation"
     3.5      let folderType: FolderType
     3.6      let accountEmail: String
     3.7 -    let connectInfo: ImapSmtpConnectInfo
     3.8 +    let connectInfo: EmailConnectInfo
     3.9      let connectionManager: ConnectionManager
    3.10      var folderName: String
    3.11      var imapSync: ImapSync!
     4.1 --- a/pEpForiOS/Background/FetchFoldersOperation.swift	Mon Oct 24 23:57:03 2016 +0200
     4.2 +++ b/pEpForiOS/Background/FetchFoldersOperation.swift	Tue Oct 25 00:48:01 2016 +0200
     4.3 @@ -12,11 +12,11 @@
     4.4  import MessageModel
     4.5  
     4.6  open class ImapFolderBuilder: NSObject, CWFolderBuilding {
     4.7 -    let connectInfo: ImapSmtpConnectInfo
     4.8 +    let connectInfo: EmailConnectInfo
     4.9      let coreDataUtil: CoreDataUtil
    4.10      open let backgroundQueue: OperationQueue?
    4.11  
    4.12 -    public init(coreDataUtil: CoreDataUtil, connectInfo: ImapSmtpConnectInfo,
    4.13 +    public init(coreDataUtil: CoreDataUtil, connectInfo: EmailConnectInfo,
    4.14                  backgroundQueue: OperationQueue) {
    4.15          self.connectInfo = connectInfo
    4.16          self.coreDataUtil = coreDataUtil
    4.17 @@ -42,7 +42,7 @@
    4.18  open class FetchFoldersOperation: ConcurrentBaseOperation {
    4.19      let comp = "FetchFoldersOperation"
    4.20      var imapSync: ImapSync!
    4.21 -    let connectInfo: ImapSmtpConnectInfo
    4.22 +    let connectInfo: EmailConnectInfo
    4.23      let connectionManager: ConnectionManager
    4.24      var folderBuilder: ImapFolderBuilder!
    4.25  
    4.26 @@ -52,7 +52,7 @@
    4.27       */
    4.28      let onlyUpdateIfNecessary: Bool
    4.29  
    4.30 -    public init(connectInfo: ImapSmtpConnectInfo, coreDataUtil: CoreDataUtil,
    4.31 +    public init(connectInfo: EmailConnectInfo, coreDataUtil: CoreDataUtil,
    4.32                  connectionManager: ConnectionManager, onlyUpdateIfNecessary: Bool) {
    4.33          self.onlyUpdateIfNecessary = onlyUpdateIfNecessary
    4.34          self.connectInfo = connectInfo
    4.35 @@ -65,7 +65,7 @@
    4.36                                                 backgroundQueue: backgroundQueue)
    4.37      }
    4.38  
    4.39 -    convenience public init(connectInfo: ImapSmtpConnectInfo, coreDataUtil: CoreDataUtil,
    4.40 +    convenience public init(connectInfo: EmailConnectInfo, coreDataUtil: CoreDataUtil,
    4.41                              connectionManager: ConnectionManager) {
    4.42          self.init(connectInfo: connectInfo, coreDataUtil: coreDataUtil,
    4.43                    connectionManager: connectionManager, onlyUpdateIfNecessary: false)
    4.44 @@ -85,7 +85,7 @@
    4.45                  var needSync = false
    4.46                  let requiredTypes: [FolderType] = [.inbox, .sent, .drafts, .trash]
    4.47                  for ty in requiredTypes {
    4.48 -                    if self.model.folderByType(ty, email: self.connectInfo.email) == nil {
    4.49 +                    if self.model.folderByType(ty, email: self.connectInfo.userId) == nil {
    4.50                          needSync = true
    4.51                          break
    4.52                      }
    4.53 @@ -185,7 +185,7 @@
    4.54          let folderInfo = FolderInfo.init(name: folderName, separator: folderSeparator)
    4.55          let op = StoreFolderOperation.init(
    4.56              coreDataUtil: coreDataUtil, folderInfo: folderInfo,
    4.57 -            email: self.connectInfo.email)
    4.58 +            email: self.connectInfo.userId)
    4.59          backgroundQueue.addOperation(op)
    4.60      }
    4.61  
     5.1 --- a/pEpForiOS/Background/GrandOperator.swift	Mon Oct 24 23:57:03 2016 +0200
     5.2 +++ b/pEpForiOS/Background/GrandOperator.swift	Tue Oct 25 00:48:01 2016 +0200
     5.3 @@ -43,10 +43,10 @@
     5.4       - parameter completionBlock: Will be called on completion of the operation, with
     5.5       a non-nil error object if there was an error during execution.
     5.6       */
     5.7 -    func fetchFolders(_ connectInfo: ImapSmtpConnectInfo, completionBlock: GrandOperatorCompletionBlock?)
     5.8 +    func fetchFolders(_ connectInfo: EmailConnectInfo, completionBlock: GrandOperatorCompletionBlock?)
     5.9  
    5.10      /**
    5.11 -     Asychronously fetches mails for the given `ImapSmtpConnectInfo`s
    5.12 +     Asychronously fetches mails for the given `EmailConnectInfo`s
    5.13       and the given folder name and stores them into the persistent store.
    5.14       Will also decrypt them, and fetch folders if necessary.
    5.15  
    5.16 @@ -55,7 +55,7 @@
    5.17       a non-nil error object if there was an error during execution.
    5.18       */
    5.19      func fetchEmailsAndDecryptImapSmtp(
    5.20 -        connectInfos: [ImapSmtpConnectInfo], folderName: String?,
    5.21 +        connectInfos: [EmailConnectInfo], folderName: String?,
    5.22          completionBlock: GrandOperatorCompletionBlock?)
    5.23  
    5.24      /**
    5.25 @@ -72,7 +72,7 @@
    5.26       Asynchronously verifies the given connection. Tests for IMAP and SMTP. The test is considered
    5.27       a success when authentication was successful.
    5.28       */
    5.29 -    func verifyConnection(_ connectInfo: ImapSmtpConnectInfo, completionBlock: GrandOperatorCompletionBlock?)
    5.30 +    func verifyConnection(_ connectInfo: EmailConnectInfo, completionBlock: GrandOperatorCompletionBlock?)
    5.31  
    5.32      /**
    5.33       Sends the given mail via SMTP. Also saves it into the drafts folder. You
    5.34 @@ -186,7 +186,7 @@
    5.35          op.start()
    5.36      }
    5.37  
    5.38 -    open func fetchFolders(_ connectInfo: ImapSmtpConnectInfo,
    5.39 +    open func fetchFolders(_ connectInfo: EmailConnectInfo,
    5.40                               completionBlock: GrandOperatorCompletionBlock?) {
    5.41          let op = FetchFoldersOperation.init(
    5.42              connectInfo: connectInfo, coreDataUtil: coreDataUtil,
    5.43 @@ -195,7 +195,7 @@
    5.44      }
    5.45  
    5.46      open func fetchEmailsAndDecryptImapSmtp(
    5.47 -        connectInfos: [ImapSmtpConnectInfo], folderName: String?,
    5.48 +        connectInfos: [EmailConnectInfo], folderName: String?,
    5.49          completionBlock: GrandOperatorCompletionBlock?) {
    5.50          var operations = [BaseOperation]()
    5.51          var fetchOperations = [BaseOperation]()
    5.52 @@ -203,7 +203,7 @@
    5.53          for connectInfo in connectInfos {
    5.54              operations.append(CreateLocalSpecialFoldersOperation.init(
    5.55                  coreDataUtil: coreDataUtil,
    5.56 -                accountEmail: connectInfo.email))
    5.57 +                accountEmail: connectInfo.userId))
    5.58              operations.append(FetchFoldersOperation.init(
    5.59                  connectInfo: connectInfo, coreDataUtil: coreDataUtil,
    5.60                  connectionManager: connectionManager, onlyUpdateIfNecessary: true))
    5.61 @@ -257,7 +257,7 @@
    5.62          }
    5.63      }
    5.64  
    5.65 -    open func verifyConnection(_ connectInfo: ImapSmtpConnectInfo,
    5.66 +    open func verifyConnection(_ connectInfo: EmailConnectInfo,
    5.67                                   completionBlock: GrandOperatorCompletionBlock?) {
    5.68          let op1 = VerifyImapConnectionOperation.init(grandOperator: self, connectInfo: connectInfo)
    5.69          let op2 = VerifySmtpConnectionOperation.init(grandOperator: self, connectInfo: connectInfo)
     6.1 --- a/pEpForiOS/Background/PrefetchEmailsOperation.swift	Mon Oct 24 23:57:03 2016 +0200
     6.2 +++ b/pEpForiOS/Background/PrefetchEmailsOperation.swift	Tue Oct 25 00:48:01 2016 +0200
     6.3 @@ -17,12 +17,12 @@
     6.4  open class PrefetchEmailsOperation: ConcurrentBaseOperation {
     6.5      let comp = "PrefetchEmailsOperation"
     6.6  
     6.7 -    let connectInfo: ImapSmtpConnectInfo
     6.8 +    let connectInfo: EmailConnectInfo
     6.9      var sync: ImapSync!
    6.10      var folderToOpen: String
    6.11      let connectionManager: ConnectionManager
    6.12  
    6.13 -    public init(grandOperator: IGrandOperator, connectInfo: ImapSmtpConnectInfo, folder: String?) {
    6.14 +    public init(grandOperator: IGrandOperator, connectInfo: EmailConnectInfo, folder: String?) {
    6.15          self.connectInfo = connectInfo
    6.16          self.connectionManager = grandOperator.connectionManager
    6.17          if let folder = folder {
     7.1 --- a/pEpForiOS/Models/CdModel.swift	Mon Oct 24 23:57:03 2016 +0200
     7.2 +++ b/pEpForiOS/Models/CdModel.swift	Tue Oct 25 00:48:01 2016 +0200
     7.3 @@ -103,7 +103,7 @@
     7.4      func setAccountAsLastUsed(_ account: CdAccount) -> CdAccount
     7.5      func fetchLastAccount() -> CdAccount?
     7.6  
     7.7 -    func insertAccountFromImapSmtpConnectInfo(_ connectInfo: ImapSmtpConnectInfo) -> CdAccount
     7.8 +    func insertAccountFromEmailConnectInfo(_ connectInfo: EmailConnectInfo) -> CdAccount
     7.9      func insertNewMessage() -> CdMessage
    7.10  
    7.11      /**
    7.12 @@ -201,6 +201,7 @@
    7.13   Core data model implementation
    7.14   */
    7.15  open class CdModel: ICdModel {
    7.16 +
    7.17      let comp = "CdModel"
    7.18  
    7.19      open static let CouldNotCreateFolder = 1000
    7.20 @@ -309,35 +310,40 @@
    7.21      func newAccountFromImapSmtpConnectInfo(_ connectInfo: EmailConnectInfo) -> CdAccount {
    7.22          let account = NSEntityDescription.insertNewObject(
    7.23              forEntityName: CdAccount.entityName(), into: context) as! CdAccount
    7.24 -        account.nameOfTheUser = connectInfo.nameOfTheUser
    7.25 -        account.email = connectInfo.email
    7.26 -        account.imapUsername = connectInfo.imapUsername
    7.27 -        account.smtpUsername = connectInfo.smtpUsername
    7.28 -        account.imapServerName = connectInfo.imapServerName
    7.29 -        account.smtpServerName = connectInfo.smtpServerName
    7.30 -        account.imapServerPort = NSNumber.init(value: Int16(connectInfo.imapServerPort) as Int16)
    7.31 -        account.smtpServerPort = NSNumber.init(value: Int16(connectInfo.smtpServerPort) as Int16)
    7.32 -        account.imapTransport = NSNumber.init(value: Int16(connectInfo.imapTransport.rawValue)
    7.33 +        account.nameOfTheUser = connectInfo.userName!
    7.34 +        account.email = connectInfo.userId
    7.35 +        
    7.36 +        // IMAP
    7.37 +        if (connectInfo.emailProtocol?.rawValue.isEqual(EmailProtocol.imap.rawValue))! {
    7.38 +            account.imapUsername = connectInfo.userName
    7.39 +            account.imapServerName = connectInfo.networkAddress
    7.40 +            account.imapServerPort = NSNumber.init(value: Int16(connectInfo.networkPort) as Int16)
    7.41 +            account.imapTransport = NSNumber.init(value: Int16((connectInfo.connectionTransport?.rawValue)!)
    7.42              as Int16)
    7.43 -        account.smtpTransport = NSNumber.init(value: Int16(connectInfo.smtpTransport.rawValue)
    7.44 +        }
    7.45 +        // SMTP
    7.46 +        else {
    7.47 +            account.smtpUsername = connectInfo.userName
    7.48 +            account.smtpServerName = connectInfo.networkAddress
    7.49 +            account.smtpServerPort = NSNumber.init(value: Int16(connectInfo.networkPort) as Int16)
    7.50 +            account.smtpTransport = NSNumber.init(value: Int16((connectInfo.connectionTransport?.rawValue)!)
    7.51              as Int16)
    7.52 +        }
    7.53  
    7.54          return account
    7.55      }
    7.56  
    7.57 -    open func insertAccountFromImapSmtpConnectInfo(_ connectInfo: EmailConnectInfo) -> CdAccount {
    7.58 -        if let ac = accountByEmail(connectInfo.email) {
    7.59 +    open func insertAccountFromEmailConnectInfo(_ connectInfo: EmailConnectInfo) -> CdAccount {
    7.60 +        if let ac = accountByEmail(connectInfo.userId) {
    7.61              return ac
    7.62          }
    7.63  
    7.64          let account = newAccountFromImapSmtpConnectInfo(connectInfo)
    7.65          save()
    7.66 +        // An SMTP and IMAP account are considered seperate.
    7.67          let _ = KeyChain.addEmail(connectInfo.userId,
    7.68 -                                  serverType: Server.ServerType.imap.asString(),
    7.69 -                                  password: connectInfo.imapPassword)
    7.70 -        let _ = KeyChain.addEmail(connectInfo.userId,
    7.71 -                                  serverType: Server.ServerType.smtp.asString(),
    7.72 -                                  password: connectInfo.getSmtpPassword())
    7.73 +                                  serverType: (connectInfo.emailProtocol?.rawValue)!,
    7.74 +                                  password: connectInfo.userPassword)
    7.75          return account
    7.76      }
    7.77  
     8.1 --- a/pEpForiOS/Network/EmailConnectInfo.swift	Mon Oct 24 23:57:03 2016 +0200
     8.2 +++ b/pEpForiOS/Network/EmailConnectInfo.swift	Tue Oct 25 00:48:01 2016 +0200
     8.3 @@ -64,16 +64,14 @@
     8.4   Holds additional connection info (like server, port etc.) for IMAP and SMTP.
     8.5   */
     8.6  public protocol IEmailConnectInfo: IConnectInfo {
     8.7 -    var emailProtocol: EmailProtocol { get }
     8.8 -    
     8.9 +    var emailProtocol: EmailProtocol? { get }
    8.10      var connectionTransport: ConnectionTransport? { get }
    8.11      var userPassword: String? { get }
    8.12      var authMethod: AuthMethod? { get }
    8.13  }
    8.14  
    8.15  public class EmailConnectInfo: ConnectInfo {
    8.16 -    public var emailProtocol: EmailProtocol
    8.17 -
    8.18 +    public var emailProtocol: EmailProtocol?
    8.19      public var connectionTransport: ConnectionTransport?
    8.20      public var userPassword: String?
    8.21      public var authMethod: AuthMethod?