Hey there!
I created an algorithm that does this, I want to know everyone’s opinion here. I’m new to javascript and I’ve been using delta.chat for 2 months now, I found this topic interesting and wanted to help.
my reasons
I think this feature is important because it will turn delta.chat into something more like chat. Generally, when we open the app we have to enter the email address and some email settings to receive and send messages. Instead of typing the email, you just type the number and the system can automatically configure any setting.
Another reason for this feature would be the purpose of disclosing contact emails, without the contact emails appearing as contact emails, but on the contrary as phone numbers.
Another advantage of the algorithm if there is interest, could implement the generation of phone numbers randomly based on the ascii table, unicode, alphabet or common order and randomness as well. It would be possible to have different types of mailPhone number, different patterns if the mailPhone pattern were adopted.
algorithm.js
// check if email is valid(return value) or if "false" without value
// console.log(testMail('abc@abc.com'));
function testMail(string_mail) {
const re = /\S+@\S+\.\S+/;
if(re.test(string_mail)){
return true; // return with value
}
else {
return ''; // return without value, false, '';
}
}
// Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.
// example: generatePhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890"
function generatePhoneNumber(numbers){
// patterns: '+979 (8) 996-4-979' or '+97 (98) 9964-9798 9946-9911 110' for 'a (b) c@ .com' etc
let format = "(xx-xx-xx)-xx-(xx-xx-xx)-xx-(xx-xxx-xxx)"; //"+xx (xx) xxxx-xxxxxx-xxxxxxxxxx"; // a b c @ab c.def -> +123 (0) 123-0-456 -> abc(@)-.-def
for(let i = 0; i < numbers.length; i++){
format = format.replace('x', numbers[i]);
}
return format;
}
function getCharCodes(s){
let charCodeArr = [];
for(let i = 0; i < s.length; i++){
let code = s.charCodeAt(i);
charCodeArr.push(code);
}
let strx = charCodeArr.toString();
let withoutCommas = strx.replace(/,/g, '');
return generatePhoneNumber(withoutCommas); // 👉️ '12345.67' // generatePhoneNumber(charCodeArr.toString());
}
function encodeMailPhone(string_mail){ // 'abc@abc.com' in string_mail
if(testMail(string_mail)){
console.log('encode abc@abc.com to :', getCharCodes(string_mail)); //console.log(text); //or text.join();
}
else {
return ''; // return without value, false, '';
}
}
function decodeMailPhone(string){ // string, "(97-98-99)-64-(97-98-99)-46-(99-111-109)";
let stringEmail = string.replace('(', '').replace(')', '').replace('(', '').replace(')', '').replace('(', '').replace(')','').replace('-', ' ').replace('-', ' ').replace('-', ' ').replace('-', ' ').replace('-', ' ').replace('-', ' ').replace('-', ' ').replace('-', ' ').replace('-', ' ').replace('-', ' ');
let array = stringEmail.split(" ");
console.log('decode (97-98-99)-64-(97-98-99)-46-(99-111-109) to:', String.fromCharCode(...array)); // String.fromCharCode(72, 69, 76, 76, 79); or characters
}
encodeMailPhone('abc@abc.com');//=> abc@abc.com => 97 98 99 64 97 98 99 46 99 111 109 => (97-98-99)-64-(97-98-99)-46-(99-111-109)
decodeMailPhone("(97-98-99)-64-(97-98-99)-46-(99-111-109)"); //output: (97-98-99)-64-(97-98-99)-46-(99-111-109) => 97 98 99 64 97 98 99 46 99 111 109 => abc@abc.com
The algorithm validates the email address, after this validation process, the algorithm takes the email address and transforms it into an ascii sequence, this ascii sequence has a positional criterion, so it is the same written form of the email, but kept only with numerical characters represented by the position of the character in the ascii table. There is another way to transform an email address into a phone number, which could be the same way of querying the ascii table to the unicode table or the alphanumeric table that can have a common or random ordering. Please see my code on pastebin pastebin/raw/f3zQ9VTe
sample.html
<!DOCTYPE html>
<html>
<head>
<title>Sample mailPhone and Qrcode</title>
<!--- delta-chat, qrcode, mailPhone --->
<script src="https://github.com/davidshimjs/qrcodejs.js"/></script>
</head>
<body>
<div id="qrcode"></div>
<script type="text/javascript">
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: 'abc@abc.com', // or: 'sample@domain.com' // or: ' (97-98-99)-64-(97-98-99)-46-(99-111-109) '
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
</script>
</body>
</html>
As we can see in this html file, we have a js library to create a qrcode from mail or mailPhone. The advantage of this resource I observe today that it can be used to disclose the number by qrcode. That way, when the person reads the qrcode, he then has access to the number, adding the cell phone number, it is possible that this number is saved in his main contact book or in the cloud.
ui/ux
As we can see in this conceptual image, we can have several contact numbers that are ways of representing the email. You can save email numbers within your contact book locally or in the cloud. The advantage of this contact number being saved in your calendar or cloud is that there is no way to know if the number is an email or not, which guarantees certain anonymity of the contacts you have by email, but they are seen as cell phone numbers. Please see this code here
Safety
If there is any leak of information, data or spam to any mailPhone, you can delete the mailPhone contact, and you will not receive that message anymore. From the user’s point of view, it is easier to delete the contact number or block a contact number than by email.
Another interesting idea, is to think that mailPhone is something similar to the tor project, you can redirect a list of mailPhone to different people and routes too, so that you don’t know the origin of the email sent or received. Not even the email header. This usually ensures or prevents spam, trojans, phishing, and other types of email attacks. Either you have an unalterable mailPhone with a changeable username, or you have a changeable mailPhone (which changes) with an unchangeable username. So It might be interesting for you to have a public mailPhone and a private mailPhone. So the private mailPhone(only a list of private contacts you trust, can be accessed by your mailPhone). And even if those contacts share your mailPhone without having that you know that, you can block or delete some of those contacts who shared your mailPhone. You can delete the number associated with mailPhone or the email associated with MailPhone. But just like you can use the public mailPhone, where you configure routes or which contacts are available.
Today there are linux smartphones, in theory you could set up a hardware key built into these linux devices so that only those devices communicate with each other. That is, if there is any external communication, this is routed to other devices outside the network to prevent some external attack on an internal network, which these two devices are communicating with the mailPhone.
License
The algorithm license is under Mit, but can be changed if there is interest in delta.chat