
'use strict';

var appCfg = {};

var ngModule = angular.module('woAppConfig', []);
ngModule.factory('appConfig', function() {
    return appCfg;
});
module.exports = appCfg;

/**
 * Global app configurations
 */
console.log('location', window.location);
appCfg.config = {
    pgpComment: 'Serious Mail',
    keyServerUrl: window.location.origin,
    hkpUrl: 'http://keyserver.ubuntu.com',
    adminUrl: window.location.origin + '/admin',
    settingsUrl: window.location.origin + '/autodiscovery/',
    mailServer: {
        domain: '*',
        imap: {
            hostname: 'localhost',
            port: 143,
            secure: false,
            requireTLS: true,
            ignoreTLS: false
        },
        smtp: {
            hostname: 'localhost',
            port: 587,
            secure: false,
            requireTLS: true,
            ignoreTLS: false
        }
    },
    oauthDomains: [/\.gmail\.com$/, /\.googlemail\.com$/],
    ignoreUploadOnSentDomains: [/\.gmail\.com$/, /\.googlemail\.com$/],
    serverPrivateKeyId: 'EE342F0DDBB0F3BE',
    symKeySize: 256,
    symIvSize: 96,
    asymKeySize: 2048,
    workerPath: 'js',
    reconnectInterval: 10000,
    checkOutboxInterval: 5000,
    iconPath: '/img/icon-128-chrome.png',
    verificationUrl: '/verify/',
    verificationUuidLength: 36,
    dbVersion: 6,
    appVersion: undefined,
    outboxMailboxPath: 'OUTBOX',
    outboxMailboxName: 'Outbox',
    outboxMailboxType: 'Outbox',
    connDocTimeout: 5000,
    imapUpdateBatchSize: 25
};

// parse manifest to get configurations for current runtime
if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.getManifest) {
    setConfigParams(chrome.runtime.getManifest());
} else if (typeof $ !== 'undefined' && $.get) {
    $.get('/manifest.json', setConfigParams, 'json');
}

function setConfigParams(manifest) {
    var cfg = appCfg.config;

    function getUrl(beginsWith) {
        return _.find(manifest.permissions, function(permission) {
            return typeof permission === 'string' && permission.indexOf(beginsWith) === 0;
        }).replace(/\/$/, ''); // remove last '/' from url due to required syntax in manifest
    }

    // get key server base url
    cfg.keyServerUrl = getUrl('https://keys');
    // get the app version
    cfg.appVersion = manifest.version;
}

/**
 * Strings are maintained here
 */
appCfg.string = {
    fallbackSubject: '(no subject)',
    invitationSubject: 'Invitation to a private conversation',
    invitationMessage: 'Hi,\n\nI use Serious Mail to send and receive encrypted email. I would like to exchange encrypted messages with you as well.\n\nPlease install a GPG Mail application. This application makes it easy to read and write messages securely with PGP encryption applied.\n\n',
    signature: '\n\n\n--\nSent from Serious Mail - https://seriousmumbo.com\n\nMy PGP key: ',
    webSite: 'http://seriousmumbo.com',
    verificationSubject: '[seriousmail] New public key uploaded',
    sendBtnClear: 'Send',
    sendBtnSecure: 'Send securely',
    updatePublicKeyTitle: 'Public Key Updated',
    updatePublicKeyMsgNewKey: '{0} updated his key and may not be able to read encrypted messages sent with his old key. Update the key?',
    updatePublicKeyMsgRemovedKey: '{0} revoked his key and may no longer be able to read encrypted messages. Remove the key?',
    updatePublicKeyPosBtn: 'Yes',
    updatePublicKeyNegBtn: 'No',
    outdatedCertificateTitle: 'Warning',
    outdatedCertificateMessage: 'The SSL certificate for the mail server {0} changed, the connection was refused.',
    updateCertificateTitle: 'Warning',
    updateCertificateMessage: 'The SSL certificate for the mail server {0} changed. Do you want to proceed?',
    updateCertificatePosBtn: 'Yes',
    updateCertificateNegBtn: 'No',
    certificateFaqLink: '/faq/what-does-the-ssl-certificate-for-the-mail-server--changed-mean',
    bugReportTitle: 'Report a bug',
    bugReportSubject: '[Bug] I want to report a bug',
    bugReportBody: 'Steps to reproduce\n1. \n2. \n3. \n\nWhat happens?\n\n\nWhat do you expect to happen instead?\n\n\n\n== PLEASE DONT PUT ANY KEYS HERE! ==\n\n\n## Log\n\nBelow is the log. It includes your interactions with your email provider from the point where you started the app for the last time. Login data and email content has been stripped. Any information provided by you will be used for the purpose of locating and fixing the bug you reported. It will be deleted subsequently. However, you can edit this log and/or remove log data in the event that something would show up.\n\nUser-Agent: {0}\nVersion: {1}\n\n',
    supportAddress: 'support@seriousmumbo.com',
    connDocOffline: 'It appears that you are offline. Please retry when you are online.',
    connDocTlsWrongCert: 'A connection to {0} was rejected because the TLS certificate is invalid. Please have a look at the FAQ for information on how to fix this error.',
    connDocHostUnreachable: 'We could not establish a connection to {0}. Please check the server settings!',
    connDocHostTimeout: 'We could not establish a connection to {0} within {1} ms. Please check the server settings and encryption mode!',
    connDocAuthRejected: 'Your credentials for {0} were rejected. Please check your username and password!',
    connDocNoInbox: 'We could not detect an IMAP inbox folder on {0}.  Please have a look at the FAQ for information on how to fix this error.',
    connDocGenericError: 'There was an error connecting to {0}: {1}',
    logoutTitle: 'Logout',
    logoutMessage: 'Are you sure you want to log out? Please back up your encryption key before proceeding!',
    removePreAuthAccountTitle: 'Remove account',
    removePreAuthAccountMessage: 'Are you sure you want to remove your account from this device?',
    mailchimpListId: '',
    mailchimpApiKey: '52ea5a9e1be9e1d194f184158_6538e8f09f',
    mailChimpEndPoint: 'http://seriousmail.us8.list-manage.com/'

};
@@ -302,16 +302,18 @@
 l',%0A    
+//
 keyServe
@@ -342,16 +342,59 @@
 origin,%0A
+    keyServerUrl: 'http://localhost:8000',%0A
     hkpU

update to use local keyserver, node-gpg-keyserver