forked from rinkp/custommailcow-ldap
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finalize automatic signature creation
- Loading branch information
Showing
4 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,13 @@ import { DataSource, Repository } from 'typeorm'; | |
import { ContainerConfig, Defaults, SOGoMailIdentity } from './types'; | ||
import { SogoUserProfile } from './entities/SogoUserProfile'; | ||
import { Users } from './entities/User'; | ||
import { getLDAPDisplayName } from './index'; | ||
import axios from 'axios'; | ||
|
||
// Connection options for the DB | ||
let dataSource : DataSource; | ||
let SogoUserProfileRepository: Repository<SogoUserProfile>; | ||
|
||
|
||
/** | ||
* Initialize database connection. Setup database if it does not yet exist | ||
*/ | ||
|
@@ -33,7 +34,7 @@ export async function initializeMailcowDB(config: ContainerConfig): Promise<void | |
} | ||
|
||
export async function editUserSignature(user: Users, SOBs: string[]): Promise<void> { | ||
if (user.email !== '[email protected]') return; | ||
if (user.email !== '[email protected]' && user.email !== '[email protected]') return; | ||
console.log(`Changing signatures for ${user.email}`); | ||
|
||
let profile = await SogoUserProfileRepository.findOneOrFail({ | ||
|
@@ -46,25 +47,31 @@ export async function editUserSignature(user: Users, SOBs: string[]): Promise<vo | |
let newIdentities : SOGoMailIdentity[] = []; | ||
|
||
for (let identity of cDefaults.SOGoMailIdentities) { | ||
if (!identity.isAutoGenerated) { | ||
if (identity.signature.indexOf('class="autogenerated"') === -1) { | ||
newIdentities.push(identity); | ||
} | ||
} | ||
|
||
for (let identityMail of SOBs) { | ||
const committeeDisplayName = await getLDAPDisplayName(identityMail); | ||
let signature : string = (await axios.get(`https://signature.gewis.nl/${identityMail}`)).data; | ||
signature = signature.replace('{{displayName}}', user.displayName); | ||
signature = signature.replaceAll('{{committeeDisplayName}}', committeeDisplayName); | ||
signature = signature.replaceAll('{{identityMail}}', identityMail); | ||
|
||
signature.replaceAll('', ''); | ||
|
||
let newIdentity : SOGoMailIdentity = { | ||
email: identityMail, | ||
isAutoGenerated: true, | ||
fullName: `${user.displayName}`, | ||
fullName: `${user.displayName} | ${committeeDisplayName}`, | ||
replyTo: user.email, | ||
signature: 'SIGNATURE FOR', | ||
signature: `${signature}`, | ||
}; | ||
newIdentities.push(newIdentity); | ||
} | ||
|
||
cDefaults.SOGoMailIdentities = newIdentities; | ||
profile.c_defaults = JSON.stringify(cDefaults); | ||
console.log(cDefaults.SOGoMailIdentities); | ||
|
||
await SogoUserProfileRepository.update(user.email, profile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.