Solved

JScript parsing

Posted on 2004-10-20
14
207 Views
Last Modified: 2008-02-01
You can run this script with Windows Scripting Host by invoking
cscript.exe from the Windows command shell, or by using wscript.exe
from Windows Explorer.

var emailaddr = null;
var subject = null;
var objArgs = WScript.Arguments;
if(objArgs.length >= 1) {
    emailaddr = objArgs(0);
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
}

cscript.exe mailto:test@foobar.com causes emailaddr = test@foobar.com.

I would to modify the above to have cscript.exe malito:test@foobar.com?Subject=help to cause emailaddr = test@foobar.com and then subject=help

THANKS!
0
Comment
Question by:rw263
  • 8
  • 6
14 Comments
 
LVL 30

Expert Comment

by:third
ID: 12365315
try,

  var emailaddr = null;
  var subject = null;
  var objArgs = WScript.Arguments;
  if(objArgs.length >= 1) {
    var strArr = objArgs[0].split('?');
    emailaddr = strArr[0];    
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
    subject = strArr[1].split('=')[1];
  }
0
 

Author Comment

by:rw263
ID: 12365392
objArgs.0 is null or not an object
0
 
LVL 30

Expert Comment

by:third
ID: 12365454
how about,

var strArr = objArgs(0).split('?');

replacing [] with ()
0
 

Author Comment

by:rw263
ID: 12365702
mailto: strArr.1 is null or not an object
mailto:test@foo.com?subject=test => works
mailto:test@foo.com => strArr.1 is null or not an object
0
 
LVL 30

Expert Comment

by:third
ID: 12365762
ok here,

if(strArr.length >= 2){
  subject = strArr[1].split('=')[1];
}
0
 

Author Comment

by:rw263
ID: 12365835
Almost there!!

mailto: -=> works
mailto:test@foo.com -=> works
mailto:test@foo.com?subject=test -=> works
mailto:test@foo.com?abc=test -=> causes emailaddr = test@foo.com, subect = test, here the email is correct, there is no subject specified though....
0
 
LVL 30

Expert Comment

by:third
ID: 12365907

ok,

if((strArr.length >= 2)&&()){
  subject = strArr[1].split('=')[1];
}


var emailaddr = null;
  var subject = null;
  var objArgs = WScript.Arguments;
  if(objArgs.length >= 1) {
    var strArr = objArgs(0).split('?');
    emailaddr = strArr[0];    
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
    if(strArr.length >= 2){
      var subjectArr = strArr[1].split('=');
      if(subjectArr[0]=='subject'){
        subject = subjectArr[1];
      }
    }
   
   
  }
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:third
ID: 12365920
opps ignore the first three lines. that should not be there, my bad.

var emailaddr = null;
  var subject = null;
  var objArgs = WScript.Arguments;
  if(objArgs.length >= 1) {
    var strArr = objArgs(0).split('?');
    emailaddr = strArr[0];    
    if(emailaddr.substr(0, 7) == "mailto:")
        emailaddr = emailaddr.substr(7);
    if(strArr.length >= 2){
      var subjectArr = strArr[1].split('=');
      if(subjectArr[0]=='subject'){
        subject = subjectArr[1];
      }
    }  
  }
0
 
LVL 30

Expert Comment

by:third
ID: 12365948
better change this

if(subjectArr[0]=='subject')

to

if(subjectArr[0].toLowerCase()=='subject')
0
 

Author Comment

by:rw263
ID: 12366012
mailto: -=> works
mailto:test@foo.com -=> works, but subject comes up as null, should be blank
mailto:test@foo.com?subject=test -=> works
mailto:test@foo.com?abc=test -=> causes emailaddr = test@foo.com, subect = null, should come up as blank
mailto:test@foo.com?Subject=test -=> subject is blank (should be case insensative on SubJect

so close... thanks!!!!
0
 
LVL 30

Accepted Solution

by:
third earned 500 total points
ID: 12366049
you can initialize it to ''

var emailaddr = '';
var subject = '';

for the case sensitivity issue, i provided the answer above.
0
 

Author Comment

by:rw263
ID: 12366070
yahoo!!!

Don't understand all the code, but it works great! THANKS!!
0
 

Author Comment

by:rw263
ID: 12366079
var emailaddr = "";
var subject = "";
var objArgs = WScript.Arguments;

if(objArgs.length >= 1) {
  var strArr = objArgs(0).split('?');
  emailaddr = strArr[0];
  if(emailaddr.substr(0, 7) == "mailto:") {
    emailaddr = emailaddr.substr(7);
    if (strArr.length >= 2) {
      var subjectArr = strArr[1].split('=');
      if (subjectArr[0].toLowerCase() == 'subject')
        subject = subjectArr[1];
    }
  }
}
0
 
LVL 30

Expert Comment

by:third
ID: 12366129
welcome.

;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now