Solved

JScript parsing

Posted on 2004-10-20
14
208 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

813 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

11 Experts available now in Live!

Get 1:1 Help Now