<commit_before>Account = require './account'
Mailbox = require './mailbox'
ImapScheduler = require '../processes/imap_scheduler'
ImapReporter = require '../processes/imap_reporter'
Promise = require 'bluebird'
log = require('../utils/logging')(prefix: 'models:account_imap')
Compiler    = require 'nodemailer/src/compiler'
# functions of an account linked to imap


Account::makeImapConfig = ->
    id: @_id
    user: @login
    label: @label
    password: <PASSWORD>
    host: @imapServer
    port: parseInt @imapPort
    tls: not @imapSSL? or @imapSSL
    tlsOptions: rejectUnauthorized: false

# static function, we have 1 ImapScheduler by Account
Account::getScheduler = ->
    if @id then ImapScheduler.instanceFor @id, this
    else Promise.resolve new ImapScheduler @makeImapConfig()

Account::doASAP = (gen) ->
    @getScheduler().then (scheduler) ->
        scheduler.doASAP gen

Account::imap_getBoxes = ->
    @doASAP (imap) -> imap.getBoxes()

# Public: refresh one account
# register a 'account-fetch' task in {ImapReporter}
#
# limitByBox - the maximum {Number} of message to fetch at once for each box
#
# Returns a {Promise} for task completion
Account::imap_fetchMails = (limitByBox) ->
    reporter = null
    Mailbox.getBoxes @id
    .tap (boxes) ->
        reporter = ImapReporter.accountFetch this, boxes.length
    .serie (box) =>
        box.imap_fetchMails limitByBox
        .catch (err) -> reporter.onError err
        .tap         -> reporter.addProgress 1
    .finally -> reporter.onDone()

# Public: create a mail in the given box
# used for drafts
#
# box - the {Mailbox} to create mail into
# message - a {Message} to create
#
# Returns a {Promise} for the box & UID of the created mail
Account::imap_createMail = (box, message) ->

    # compile the message to text<commit_msg>[bugfix] reporter didn't have an account<commit_after>Account = require './account'
Mailbox = require './mailbox'
ImapScheduler = require '../processes/imap_scheduler'
ImapReporter = require '../processes/imap_reporter'
Promise = require 'bluebird'
log = require('../utils/logging')(prefix: 'models:account_imap')
Compiler    = require 'nodemailer/src/compiler'
# functions of an account linked to imap


Account::makeImapConfig = ->
    id: @_id
    user: @login
    label: @label
    password: <PASSWORD>
    host: @imapServer
    port: parseInt @imapPort
    tls: not @imapSSL? or @imapSSL
    tlsOptions: rejectUnauthorized: false

# static function, we have 1 ImapScheduler by Account
Account::getScheduler = ->
    if @id then ImapScheduler.instanceFor @id, this
    else Promise.resolve new ImapScheduler @makeImapConfig()

Account::doASAP = (gen) ->
    @getScheduler().then (scheduler) ->
        scheduler.doASAP gen

Account::imap_getBoxes = ->
    @doASAP (imap) -> imap.getBoxes()

# Public: refresh one account
# register a 'account-fetch' task in {ImapReporter}
#
# limitByBox - the maximum {Number} of message to fetch at once for each box
#
# Returns a {Promise} for task completion
Account::imap_fetchMails = (limitByBox) ->
    reporter = null
    Mailbox.getBoxes @id
    .tap (boxes) =>
        reporter = ImapReporter.accountFetch this, boxes.length
    .serie (box) =>
        box.imap_fetchMails limitByBox
        .catch (err) -> reporter.onError err
        .tap         -> reporter.addProgress 1
    .finally -> reporter.onDone()

# Public: create a mail in the given box
# used for drafts
#
# box - the {Mailbox} to create mail into
# message - a {Message} to create
#
# Returns a {Promise} for the box & UID of the created mail
Account::imap_createMail = (box, message) ->

    # compile the message to text
{'fraction_non_alphanumeric': 0.1122085048010974, 'fraction_numerical': 0.0010973936899862826, 'mean_word_length': 3.4736196319018404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '648955', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1144, 'n_words': 356}