 async = require 'async'
-jade = require 'jade'
-fs = require 'fs'
-log = require('printit')
+fs    = require 'fs'
+jade  = require 'jade'
+os    = require 'os'
+path  = require 'path'
+log   = require('printit')
     prefix: 'MailHandler'
     date: true
 
+cozydb = require 'cozydb'
 Event = require '../models/event'
-User = require '../models/user'
-cozydb = require 'cozydb'
+User  = require '../models/user'
+
+{VCalendar} = require 'cozy-ical'
+
 
 localization = require '../libs/localization_manager'
 

                html:    htmlTemplate templateOptions
                content: localization.t templateKey, templateOptions

            # Send mail through CozyDB API
            cozydb.api.sendMailFromUser mailOptions, (err) ->
                if err
                    log.error "An error occured while sending invitation"
                    log.error err
                else
                    needSaving   = true
                    guest.status = 'NEEDS-ACTION' # ical = waiting an answer

                done err

        # Catch errors when doing async foreach
        , (err) ->

                date: date
            htmlTemplate = localization.getEmailTemplate 'mail_delete'
            subjectKey = 'email delete title'
            subject = localization.t subjectKey, description: event.description
            mailOptions =
                to: guest.email
                subject: subject
                content: localization.t 'email delete content', templateOptions
                html: htmlTemplate templateOptions
            cozydb.api.sendMailFromUser mailOptions, (err) ->
