Shoutbox

Origin to email? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Origin to email? (/showthread.php?tid=66302)

Origin to email? by Robin4286 on 09-16-2006 at 02:46 AM

Okay, so in the message recieved event it returns the origin of the message sent. Is there a way to get the email of this origin?


RE: Origin to email? by matty on 09-16-2006 at 03:41 AM

code:
for(var enumerator = new Enumerator(pChatWnd.Contacts) ; !enumerator.atEnd(); enumerator.moveNext()){
    var Contact = enumerator.item();
    Debug.Trace('Contact.Email :'+Contact.Email);
}

Your going to have to change pChatWnd to whatever the ChatWnd object is called in the function.
RE: Origin to email? by Robin4286 on 09-16-2006 at 03:57 AM

Well thats not really accomplishing what I am trying to do. What I want to do is return who sent the email, not who is in the conversation.

Can anyone help with this?


RE: Origin to email? by cloudhunter on 09-16-2006 at 03:59 AM

It does exactly what you want. When it receives an origin, it looks for the people in the chat window, and finds out the email address. Saves iterating through all the Contacts.


RE: Origin to email? by CookieRevised on 09-16-2006 at 04:32 AM

quote:
Originally posted by cloudhunter
It does exactly what you want. When it receives an origin, it looks for the people in the chat window, and finds out the email address. Saves iterating through all the Contacts.
which will only work when there is only 1 contact in the chat though, and which you need to explicitly check on or you might end up with the wrong contact.

Also you need to check if the message doesn't come from yourself. eg: if you explicitly use what Matty posted you can end up with the contact's email, while the message was actually being send by you..

------

Robin4286

quote:
Originally posted by Robin4286
Well thats not really accomplishing what I am trying to do. What I want to do is return who sent the email, not who is in the conversation.
it is exactly what you need as you need to know who is in the conversation to check the Origin (the name) against.

So with what Matty showed, you can easly iterate thru all the contacts and getting their name and comparing it to the origin.

If there is only one contact, the iteration will be extremely short (1), if there are more than one contact, the iteration would still be short (compared to checking your whole contactlist)...


So what you need to make this:
- the code from Matty and how to iterate thru the contacts in the chat window (which is exactly what he showed).
- comparing their Name with the Origin parameter
- if a match occurs, get the email from that contact
RE: Origin to email? by markee on 09-16-2006 at 07:27 AM

quote:
Originally posted by Matty
code:
for(var enumerator = new Enumerator(pChatWnd.Contacts) ; !enumerator.atEnd(); enumerator.moveNext()){
    var Contact = enumerator.item();
    Debug.Trace('Contact.Email :'+Contact.Email);
}

Your going to have to change pChatWnd to whatever the ChatWnd object is called in the function.
Wouldn't the following code be better?
code:
for(var enumerator = new Enumerator(pChatWnd.Contacts) ; !enumerator.atEnd(); enumerator.moveNext()){
    var Cont = enumerator.item();
    if (Cont.Name === Origin){
    var Contact = Cont;
    }
}
Debug.Trace('The email of "+Origin+" is "+Contact.Email)//and you can use Contact throughout the rest of the function too

RE: Origin to email? by Robin4286 on 09-16-2006 at 06:25 PM

But, it does not return my email. I need to see if it was I who sent the email, and they cant trick it by changing their name to mine.


RE: Origin to email? by R4000 on 09-16-2006 at 06:34 PM

I use this, but it has some problems with MSGPlus not knowing the most recent names for alot of contacts.... any fix?

its like its caching them...


RE: Origin to email? by CookieRevised on 09-16-2006 at 10:50 PM

quote:
Originally posted by Robin4286
But, it does not return my email. I need to see if it was I who sent the email, and they cant trick it by changing their name to mine.
That is something different than what you asked before.

However it is based on the same stuff Matty first showed (and which markee worked out): simply compare the origin with the name of the contact(s) (or in your case with your name).

To know from whom the name Origin is, you need to know who is in the conversation and iterate all those contacts, just the same as what you requested here: "Checking who is in a conversation"


Read the Script Documentation, it actually shows you how to see the difference and it also explains why the chance is extremely extremely slim that you will get a false match. Together with that it also gives a big hint in how to totally erase a false match.
RE: Origin to email? by markee on 09-22-2006 at 06:07 AM

I also have to add that there is a great flaw in the origin variable that I came across the other day.  If you are using First and Last names to display your contacts (I think this will also happen with customized nicknames through WLM) origin will be the first and last name rather than the display name and you cannot compare this to the likes of Contact.Name as this uses their display name.  Maybe someone knows how to get past this problem, it would help a lot if you could shed some light as this could become quite a problem though I also understand that the messenger protocol probably only sends the information from the origin variable and nothing else to associate it with the contact.


RE: Origin to email? by Deco on 09-22-2006 at 09:59 PM

Here's my two cents:

First off you need to compare the origin so that you don't get your own email since whenever you send a message you get a "message received" event with yourself as origin.

Secondly the code comparing Contact.name will only work if you don't have Nickname for that person. Since Contact.Name is what they use as name and Origin might be what you use as their nickname.

Thirdly this instead of getting the contacts from the chatwindow, gets the contacts from your contact list. Might be a little longer but it'll work when  you have more than one person in the chat window.

function GetContactEmail(Name) {
var Result = "";
var Contacts = Messenger.MyContacts;
    var e = new Enumerator(Contacts);
    for (;!e.atEnd();e.moveNext()) {
        var Contact = e.item();
        if(Contact.Name == Name) {
        Result = Contact.Email;
                }
    }
    return Result;
}

Just an idea :)

Have fun!


RE: RE: Origin to email? by CookieRevised on 09-22-2006 at 10:54 PM

quote:
Originally posted by Deco
Thirdly this instead of getting the contacts from the chatwindow, gets the contacts from your contact list. Might be a little longer but it'll work when  you have more than one person in the chat window.

function GetContactEmail(Name) {
var Result = "";
var Contacts = Messenger.MyContacts;
    var e = new Enumerator(Contacts);
    for (;!e.atEnd();e.moveNext()) {
        var Contact = e.item();
        if(Contact.Name == Name) {
        Result = Contact.Email;
                }
    }
    return Result;
}
When you have more than one person in the chat window, simply use ChatWnd.Contacts. In fact you must use it anyways  anyhow and you must check for all (even if it is only 1) contacts like that.

Using the contactlist window contacts will:
a) make this unneeded longer
b) make the (though very remote) chance of getting a false positive much higher. Since two people can have the same name. The chance that two people have the same name is much larger in a larger list.
c) will fail if a contact is in the chat window which is not in your contact list (which is quite possible in multiple contact chats)