Solved

JScript parsing

Posted on 2004-10-20
14
205 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now