summaryrefslogtreecommitdiffstats
path: root/src/services/checks
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-03-15 11:32:41 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-03-15 11:32:41 +0100
commit3984f559e4c0a7d38cd093da08fec0c209eaa569 (patch)
tree3531d5c6c1d85efba171c8dec233b52d1b3e05bf /src/services/checks
parentef3222e8008e09d16867ea72da067bde12825c27 (diff)
Repair and fix REV and repair on import
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/services/checks')
-rw-r--r--src/services/checks/index.js2
-rw-r--r--src/services/checks/invalidREV.js56
2 files changed, 58 insertions, 0 deletions
diff --git a/src/services/checks/index.js b/src/services/checks/index.js
index de67af19..2ac0871d 100644
--- a/src/services/checks/index.js
+++ b/src/services/checks/index.js
@@ -21,9 +21,11 @@
*/
import badGenderType from './badGenderType'
+import invalidREV from './invalidREV'
import missingFN from './missingFN'
export default [
badGenderType,
+ invalidREV,
missingFN
]
diff --git a/src/services/checks/invalidREV.js b/src/services/checks/invalidREV.js
new file mode 100644
index 00000000..b9b4a63c
--- /dev/null
+++ b/src/services/checks/invalidREV.js
@@ -0,0 +1,56 @@
+/**
+ * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+import { VCardTime } from 'ical.js'
+
+// https://tools.ietf.org/html/rfc6350#section-6.7.4
+
+export default {
+ name: 'invalid REV',
+ run: contact => {
+ try {
+ if (contact.vCard.hasProperty('rev')
+ && contact.vCard.getFirstProperty('rev').getFirstValue()
+ && contact.vCard.getFirstProperty('rev').getFirstValue().icalclass === 'vcardtime') {
+ return false
+ }
+ } catch (error) {
+ return true
+ }
+ return true
+ },
+ fix: contact => {
+ try {
+ // removing old invalid data
+ contact.vCard.removeProperty('rev')
+
+ // creatiing new value
+ const rev = new VCardTime(null, null, 'date-time')
+ rev.fromUnixTime(Date.now() / 1000)
+ contact.vCard.addPropertyWithValue('rev', rev)
+
+ return true
+ } catch (error) {
+ return false
+ }
+ }
+}