pop3wizard.es 2.49 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
2
    SPDX-FileCopyrightText: 2009-2021 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3

4
    SPDX-License-Identifier: LGPL-2.0-or-later
Laurent Montel's avatar
Laurent Montel committed
5
6
*/

7
8
9
// add this function to trim user input of whitespace when needed
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

10
var page = Dialog.addPage( "pop3wizard.ui", qsTr("Personal Settings") );
Laurent Montel's avatar
Laurent Montel committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

var userChangedServerAddress = false;

function serverChanged( arg )
{
  validateInput();
  if ( arg == "" ) {
    userChangedServerAddress = false;
  } else {
    userChangedServerAddress = true;
  }
}

function validateInput()
{
26
  if ( page.widget().incommingAddress.text.trim() == "" ) {
Laurent Montel's avatar
Laurent Montel committed
27
28
29
30
31
32
    page.setValid( false );
  } else {
    page.setValid( true );
  }
}

33
34
var stage = 1;

Laurent Montel's avatar
Laurent Montel committed
35
36
function setup()
{
37
38
39
40
41
42
43
44
45
46
47
  if ( stage == 1 ) {
    ServerTest.test( page.widget().incommingAddress.text.trim(), "pop" );
  } else {
    ServerTest.test( page.widget().outgoingAddress.text.trim(), "smtp" );
  }
}

function testResultFail()
{
  testOk( -1 );
}
Laurent Montel's avatar
Laurent Montel committed
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function testOk( arg )
{
  if (stage == 1) {
    SetupManager.openWallet();
    var pop3Res = SetupManager.createResource( "akonadi_pop3_resource" );
    var server = page.widget().incommingAddress.text.trim();
    pop3Res.setOption( "Host", server );
    pop3Res.setOption( "Login", page.widget().userName.text.trim() );
    pop3Res.setOption( "Password", SetupManager.password() );

    if ( arg == "ssl" ) {
      pop3Res.setOption( "Port", 995 );
      pop3Res.setOption( "UseTLS", true );
    } else if ( arg == "tls" ) { // tls is really STARTTLS
      pop3Res.setOption( "Port", 110 );
      pop3Res.setOption( "UseTLS", true );
    } else if ( arg == "none" ) {
      pop3Res.setOption( "Port", 110 );
    } else {
      pop3Res.setOption( "Port", 110 );
    }

    stage = 2;
    setup();
  } else {
    var smtp = SetupManager.createTransport( "smtp" );
    smtp.setName( page.widget().outgoingAddress.text.trim() );
    smtp.setHost( page.widget().outgoingAddress.text.trim() );
    if ( arg == "ssl" ) {
      smtp.setEncryption( "SSL" );
    } else if ( arg == "tls" ) {
      smtp.setEncryption( "TLS" );
    } else {
      smtp.setEncryption( "None" );
    }
    smtp.setUsername( page.widget().userName.text );
    smtp.setPassword( SetupManager.password() );
    SetupManager.execute();
  }
}
Laurent Montel's avatar
Laurent Montel committed
89

90
91
92
93
94
95
96
try {
  ServerTest.testFail.connect( testResultFail );
  ServerTest.testResult.connect( testOk );
  page.widget().incommingAddress.textChanged.connect( validateInput );
  page.pageLeftNext.connect( setup );
} catch ( e ) {
  print( e );
Laurent Montel's avatar
Laurent Montel committed
97
98
99
}

validateInput();