Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1583|回复: 0
打印 上一主题 下一主题

MailSpring源码分析

[复制链接]

1272

主题

2067

帖子

7964

积分

认证用户组

Rank: 5Rank: 5

积分
7964
跳转到指定楼层
楼主
发表于 2020-9-18 10:54:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Qter 于 2020-9-18 18:11 编辑

https://github.com/Foundry376/Mailspring/blob/master/CONTRIBUTING.md

npm install --global --production windows-build-tools

git clone https://github.com/foundry376/mailspring
cd mailspring
npm install
npm start


package.json
  1.   "scripts": {
  2.     "postinstall": "node scripts/postinstall.js",
  3.     "start": "node_modules/.bin/electron ./app --enable-logging --dev",
  4.     "lint": "grunt lint --gruntfile=app/build/Gruntfile.js --base=./",
  5.     "test": "node_modules/.bin/electron ./app --enable-logging --test",
  6.     "test-window": "node_modules/.bin/electron ./app --enable-logging --test=window",
  7.     "build": "grunt build-client --gruntfile=app/build/Gruntfile.js --base=./",
  8.     "build-docs": "grunt docs --gruntfile=app/build/Gruntfile.js --base=./ && mkdir -p app/dist-docs && cp README.md ./app/build/docs_src/README.md && gitbook --gitbook=latest build . ./app/dist-docs --log=debug --debug && rm ./app/build/docs_src/README.md && rm -rf ./app/build/docs_src/classes",
  9.     "build-licenses-file": "cat ./app/static/all_licenses_preamble.html | ./node_modules/.bin/marked > ./app/static/all_licenses.html && licext --source ./app --mode output | ./node_modules/.bin/marked >> ./app/static/all_licenses.html",
  10.     "ci-setup-mac-keychain": "grunt setup-mac-keychain --gruntfile=app/build/Gruntfile.js --base=./"
  11.   }
复制代码
app\package.json
  1. "main": "./src/browser/main.js",
复制代码
  1.   const Application = require(path.join(options.resourcePath, 'src', 'browser', 'application'))
  2.       .default;
  3.     global.application = new Application();
  4. global.application.start(options);
复制代码
app\src\browser\application.ts
    this.on('application:show-main-window', () => {
      this.openWindowsForTokenState();
    });
  1. try {
  2.       const mailsync = new MailsyncProcess(options);
  3.       await mailsync.migrate();
  4.     }
复制代码
  1.     this.on('application:add-account', ({ existingAccountJSON } = {}) => {
  2.       const onboarding = this.windowManager.get(WindowManager.ONBOARDING_WINDOW);
  3.       if (onboarding) {
  4.         onboarding.show();
  5.         onboarding.focus();
  6.       } else {
  7.         this.windowManager.ensureWindow(WindowManager.ONBOARDING_WINDOW, {
  8.           windowProps: { addingAccount: true, existingAccountJSON },
  9.           title: localized('Add Account'),
  10.         });
  11.       }
  12.     });
复制代码
  1.     ipcMain.on('account-setup-successful', () => {
  2.       this.windowManager.ensureWindow(WindowManager.MAIN_WINDOW);
  3.       const onboarding = this.windowManager.get(WindowManager.ONBOARDING_WINDOW);
  4.       if (onboarding) {
  5.         onboarding.close();
  6.       }
  7.     });
复制代码
app\internal_packages\onboarding\lib\main.ts
import { SystemStartService, WorkspaceStore, ComponentRegistry } from 'mailspring-exports';
export function activate() {
    ComponentRegistry.register(OnboardingRoot, {
    location: WorkspaceStore.Location.Center,
  });
}


app\internal_packages\onboarding\lib\onboarding-root.tsx

import AccountSettingsPageGmail from './page-account-settings-gmail';
import AccountSettingsPageIMAP from './page-account-settings-imap';

const PageComponents = {
  welcome: WelcomePage,
  tutorial: TutorialPage,
  authenticate: AuthenticatePage,
  'account-choose': AccountChoosePage,
  'account-settings': AccountSettingsPage,
  'account-settings-gmail': AccountSettingsPageGmail,
  'account-settings-imap': AccountSettingsPageIMAP,
  'account-onboarding-success': AccountOnboardingSuccess,
  'initial-preferences': InitialPreferencesPage,
  'initial-subscription': InitialSubscriptionPage,
};

render() {
    const Component = PageComponents[this.state.page];
    }

app\internal_packages\onboarding\lib\onboarding-store.ts

this._pageStack = ['account-choose', 'account-settings', 'account-settings-imap'];


app\internal_packages\onboarding\lib\page-account-settings-imap.tsx

-----------------------

app\internal_packages\onboarding\lib\page-account-settings.tsx

async submit() {
    // expanding the account settings succeeded - try to authenticate
      this.props.onConnect(account);
  }

app\internal_packages\onboarding\lib\decorators\create-page-for-form.tsx
onConnect = (updatedAccount?: Account) => {
finalizeAndValidateAccount(account)
        .then(validated => {
          OnboardingActions.moveToPage('account-onboarding-success');
          OnboardingActions.finishAndAddAccount(validated);
        })
}


app\internal_packages\onboarding\lib\onboarding-helpers.ts
export async function finalizeAndValidateAccount(account: Account) {
  // Test connections to IMAP and SMTP
  const proc = new MailsyncProcess(AppEnv.getLoadSettings());
  proc.identity = IdentityStore.identity();
  proc.account = account;
  await proc.test();

  // Record the date of successful auth
  account.authedAt = new Date();
  return account;
}

app\src\mailsync-process.ts
export class MailsyncProcess extends EventEmitter

this.binaryPath = path.join(resourcePath, 'mailsync').replace('app.asar', 'app.asar.unpacked');

   test() {
    return this._spawnAndWait('test');
  }

   _spawnAndWait(mode, { onData }: { onData?: (data: any) => void } = {}) {
    return new Promise<{ response: any; buffer: Buffer }>((resolve, reject) => {
      this._spawnProcess(mode);
      let buffer = Buffer.from([]);
      ...
   }

    _spawnProcess(mode) {
    this._proc = spawn(this.binaryPath, args, { env });
    }


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-11-27 00:32 , Processed in 0.058388 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表