]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/emailer.ts
Tests for totalRepliesFromVideoAuthor
[github/Chocobozzz/PeerTube.git] / server / lib / emailer.ts
index a888b7a72ad0f6ac188e4642f893ebaa7aa9bd8e..7484524a4542880e016e43d149a3ac0e830a5524 100644 (file)
@@ -6,8 +6,15 @@ import { JobQueue } from './job-queue'
 import { EmailPayload } from './job-queue/handlers/email'
 import { readFileSync } from 'fs-extra'
 import { WEBSERVER } from '../initializers/constants'
-import { MCommentOwnerVideo, MVideo, MVideoAbuseVideo, MVideoAccountLight, MVideoBlacklistVideo } from '../typings/models/video'
-import { MActorFollowActors, MActorFollowFollowingFullFollowerAccount, MUser } from '../typings/models'
+import {
+  MCommentOwnerVideo,
+  MVideo,
+  MVideoAbuseVideo,
+  MVideoAccountLight,
+  MVideoBlacklistLightVideo,
+  MVideoBlacklistVideo
+} from '../typings/models/video'
+import { MActorFollowActors, MActorFollowFull, MUser } from '../typings/models'
 import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import'
 
 type SendEmailOptions = {
@@ -100,14 +107,14 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + channelName + ' just published a new video',
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + channelName + ' just published a new video',
       text
     }
 
     return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
   }
 
-  addNewFollowNotification (to: string[], actorFollow: MActorFollowFollowingFullFollowerAccount, followType: 'account' | 'channel') {
+  addNewFollowNotification (to: string[], actorFollow: MActorFollowFull, followType: 'account' | 'channel') {
     const followerName = actorFollow.ActorFollower.Account.getDisplayName()
     const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName()
 
@@ -119,7 +126,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'New follower on your channel ' + followingName,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'New follower on your channel ' + followingName,
       text
     }
 
@@ -137,7 +144,23 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'New instance follower',
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'New instance follower',
+      text
+    }
+
+    return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
+  }
+
+  addAutoInstanceFollowingNotification (to: string[], actorFollow: MActorFollowActors) {
+    const text = `Hi dear admin,\n\n` +
+      `Your instance automatically followed a new instance: ${actorFollow.ActorFollowing.url}` +
+      `\n\n` +
+      `Cheers,\n` +
+      `${CONFIG.EMAIL.BODY.SIGNATURE}`
+
+    const emailPayload: EmailPayload = {
+      to,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'Auto instance following',
       text
     }
 
@@ -157,7 +180,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + `Your video ${video.name} is published`,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + `Your video ${video.name} is published`,
       text
     }
 
@@ -177,7 +200,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + `Your video import ${videoImport.getTargetIdentifier()} is finished`,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + `Your video import ${videoImport.getTargetIdentifier()} is finished`,
       text
     }
 
@@ -197,7 +220,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + `Your video import ${videoImport.getTargetIdentifier()} encountered an error`,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + `Your video import ${videoImport.getTargetIdentifier()} encountered an error`,
       text
     }
 
@@ -219,7 +242,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'New comment on your video ' + video.name,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'New comment on your video ' + video.name,
       text
     }
 
@@ -241,7 +264,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'Mention on video ' + video.name,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'Mention on video ' + video.name,
       text
     }
 
@@ -258,16 +281,16 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'Received a video abuse',
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'Received a video abuse',
       text
     }
 
     return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
   }
 
-  addVideoAutoBlacklistModeratorsNotification (to: string[], video: MVideo) {
+  addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) {
     const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list'
-    const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
+    const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath()
 
     const text = `Hi,\n\n` +
       `A recently added video was auto-blacklisted and requires moderator review before publishing.` +
@@ -281,7 +304,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'An auto-blacklisted video is awaiting review',
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'An auto-blacklisted video is awaiting review',
       text
     }
 
@@ -296,7 +319,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'New user registration on ' + WEBSERVER.HOST,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'New user registration on ' + WEBSERVER.HOST,
       text
     }
 
@@ -318,7 +341,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + `Video ${videoName} blacklisted`,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + `Video ${videoName} blacklisted`,
       text
     }
 
@@ -336,7 +359,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to,
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + `Video ${video.name} unblacklisted`,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + `Video ${video.name} unblacklisted`,
       text
     }
 
@@ -346,14 +369,14 @@ class Emailer {
   addPasswordResetEmailJob (to: string, resetPasswordUrl: string) {
     const text = `Hi dear user,\n\n` +
       `A reset password procedure for your account ${to} has been requested on ${WEBSERVER.HOST} ` +
-      `Please follow this link to reset it: ${resetPasswordUrl}\n\n` +
+      `Please follow this link to reset it: ${resetPasswordUrl}  (the link will expire within 1 hour)\n\n` +
       `If you are not the person who initiated this request, please ignore this email.\n\n` +
       `Cheers,\n` +
       `${CONFIG.EMAIL.BODY.SIGNATURE}`
 
     const emailPayload: EmailPayload = {
       to: [ to ],
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'Reset your password',
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'Reset your password',
       text
     }
 
@@ -370,7 +393,7 @@ class Emailer {
 
     const emailPayload: EmailPayload = {
       to: [ to ],
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'Verify your email',
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'Verify your email',
       text
     }
 
@@ -391,7 +414,7 @@ class Emailer {
     const to = user.email
     const emailPayload: EmailPayload = {
       to: [ to ],
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + 'Account ' + blockedWord,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + 'Account ' + blockedWord,
       text
     }
 
@@ -411,14 +434,14 @@ class Emailer {
       fromDisplayName: fromEmail,
       replyTo: fromEmail,
       to: [ CONFIG.ADMIN.EMAIL ],
-      subject: CONFIG.EMAIL.OBJECT.PREFIX + subject,
+      subject: CONFIG.EMAIL.SUBJECT.PREFIX + subject,
       text
     }
 
     return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
   }
 
-  sendMail (options: EmailPayload) {
+  async sendMail (options: EmailPayload) {
     if (!Emailer.isEnabled()) {
       throw new Error('Cannot send mail because SMTP is not configured.')
     }
@@ -427,13 +450,15 @@ class Emailer {
       ? options.fromDisplayName
       : WEBSERVER.HOST
 
-    return this.transporter.sendMail({
-      from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`,
-      replyTo: options.replyTo,
-      to: options.to.join(','),
-      subject: options.subject,
-      text: options.text
-    })
+    for (const to of options.to) {
+      await this.transporter.sendMail({
+        from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`,
+        replyTo: options.replyTo,
+        to,
+        subject: options.subject,
+        text: options.text
+      })
+    }
   }
 
   private dieOnConnectionFailure (err?: Error) {