                     infos.imapPort   = '993'
                 if not infos.smtpServer?
                     infos.smtpServer = ''
-                    infos.smtpPort   = '587'
+                    infos.smtpPort   = '465'
+                switch infos.imapPort
+                    when '993'
+                        infos.imapSSL = true
+                        infos.imapTLS = false
+                    else
+                        infos.imapSSL = false
+                        infos.imapTLS = false
+                switch infos.smtpPort
+                    when '465'
+                        infos.smtpSSL = true
+                        infos.smtpTLS = false
+                    when '587'
+                        infos.smtpSSL = false
+                        infos.smtpTLS = true
+                    else
+                        infos.smtpSSL = false
+                        infos.smtpTLS = false
                 @setState infos
 
+    _onServerParam: (target, server, type) ->
+        if (server is 'imap' and @state.imapManualPort) or
+        (server is 'smtp' and @state.smtpManualPort)
+            # port has been set manually, don't update it
+            return
+        if server is 'smtp'
+            if type is 'ssl' and target.checked
+                @setState smtpPort: 465
+            else if type is 'tls' and target.checked
+                @setState smtpPort: 587
+        else
+            if target.checked
+                @setState imapPort: 993
+            else
+                @setState imapPort: 143
+
+    _onIMAPPort: (ev) ->
+        port = ev.target.value.trim()
+        infos =
+            imapPort: port
+        switch port
+            when '993'
+                infos.imapSSL = true
+                infos.imapTLS = false
+            else
+                infos.imapSSL = false
+                infos.imapTLS = false
+        @setState infos
+
+    _onSMTPPort: (ev) ->
+        port = ev.target.value.trim()
+        infos = {}
+        switch port
+            when '465'
+                infos.smtpSSL = true
+                infos.smtpTLS = false
+            when '587'
+                infos.smtpSSL = false
+                infos.smtpTLS = true
+            else
+                infos.smtpSSL = false
+                infos.smtpTLS = false
+        console.log port, infos
+        @setState infos
 
     componentWillReceiveProps: (props) ->
 
-        console.log "Will receive", props.error, props.isWaiting, @state.errors
         # prevents the form from changing during submission
         if not props.isWaiting
             # display the account values

                            valueLink: @linkState('smtpPort'),
                            type: 'text',
                            className: 'form-control'
                    getError 'smtpServer'
                    getError 'smtpPort'
                div className: 'form-group',

        return should

    render: ->
        if @props.selectedAccount?
            titleLabel = t "account edit"
        else
