-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new tool): Outlook Safelink Decoder
Fix #897
- Loading branch information
Showing
5 changed files
with
91 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Mailbox } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Outlook Safelink decoder', | ||
path: '/safelink-decoder', | ||
description: 'Decode Outlook SafeLink links', | ||
keywords: ['outlook', 'safelink', 'decoder'], | ||
component: () => import('./safelink-decoder.vue'), | ||
icon: Mailbox, | ||
createdAt: new Date('2024-02-25'), | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/tools/safelink-decoder/safelink-decoder.service.test.ts
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { decodeSafeLinksURL } from './safelink-decoder.service'; | ||
|
||
describe('safelink-decoder', () => { | ||
describe('decodeSafeLinksURL', () => { | ||
describe('decode outlook safelink urls', () => { | ||
it('should decode basic safelink urls', () => { | ||
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&reserved=0')) | ||
.toBe('https://www.google.com/search?q=safelink&rlz=1'); | ||
}); | ||
it('should decode encoded safelink urls', () => { | ||
expect(decodeSafeLinksURL('https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dsafelink%26rlz%3D1&data=05%7C02%7C%7C1ed07253975b46da1d1508dc3443752a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638442711583216725%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BQY0HBnnxfI7pzZoxzlhZdDvYu80LwQB0zUUjrffVnk%3D&reserved=0')) | ||
.toBe('https://www.google.com/search?q=safelink&rlz=1'); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function decodeSafeLinksURL(safeLinksUrl: string) { | ||
// Decode the ATP SafeLinks URL | ||
let originalURL; | ||
|
||
try { | ||
// Decode the URL | ||
originalURL = decodeURIComponent(safeLinksUrl); | ||
|
||
// Check if it matches the SafeLinks pattern | ||
if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&data=/)) { | ||
// Extract the original URL | ||
originalURL = originalURL.split('?url=')[1].split('&data=')[0]; | ||
} | ||
else if (originalURL.match(/\.safelinks\.protection\.outlook\.com\/\?url=.+&data=/)) { | ||
// Handle the case where "&" is encoded as "&" | ||
originalURL = originalURL.split('?url=')[1].split('&data=')[0]; | ||
} | ||
else { | ||
throw new Error('Invalid SafeLinks URL provided'); | ||
} | ||
} | ||
catch (error: any) { | ||
// Handle errors | ||
throw new Error(`Failed to decode SafeLinks URL: ${error}`); | ||
} | ||
|
||
return originalURL; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script setup lang="ts"> | ||
import { decodeSafeLinksURL } from './safelink-decoder.service'; | ||
import TextareaCopyable from '@/components/TextareaCopyable.vue'; | ||
const inputSafeLinkUrl = ref(''); | ||
const outputDecodedUrl = computed(() => { | ||
try { | ||
return decodeSafeLinksURL(inputSafeLinkUrl.value); | ||
} | ||
catch (e: any) { | ||
return e.toString(); | ||
} | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<c-input-text | ||
v-model:value="inputSafeLinkUrl" | ||
raw-text | ||
placeholder="Your input Outlook SafeLink Url..." | ||
autofocus | ||
label="Your input Outlook SafeLink Url:" | ||
/> | ||
|
||
<n-divider /> | ||
|
||
<n-form-item label="Output decoded URL:"> | ||
<TextareaCopyable :value="outputDecodedUrl" :word-wrap="true" /> | ||
</n-form-item> | ||
</div> | ||
</template> |