json response is not open in new window - javascript

I want to open the json response in to the new window, i tried a lot but didn't get ant success, if any one can helps me, it will be appreciated.
this is my app.js code
Titanium.UI.setBackgroundColor('#fff');
var tabGroup = Titanium.UI.createTabGroup();
var login = Titanium.UI.createWindow({
title:'User Authentication Demo',
tabBarHidden:true,
url:'main_windows/login.js'
});
var loginTab = Titanium.UI.createTab({
title:"Login",
window:login
});
tabGroup.addTab(loginTab);
tabGroup.open();
and this is my login.js code
var win = Titanium.UI.currentWindow;
var UserLogin = Titanium.UI.createTextField({
color:'#336699',
top:10,
left:10,
width:300,
height:40,
hintText:'UserLogin',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(UserLogin);
var UserPassword = Titanium.UI.createTextField({
color:'#336699',
top:60,
left:10,
width:300,
height:40,
hintText:'UserPassword',
passwordMask:true,
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(UserPassword);
var loginBtn = Titanium.UI.createButton({
title:'Login',
top:110,
width:90,
height:35,
borderRadius:1,
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
});
win.add(loginBtn);
/*
* Login Event Handling
*/
var loginReq = Titanium.Network.createHTTPClient();
var data, User, UserName, UserEmail, UserFirstName, UserLastName, UserAvatar, BioGraphyNative,BioGraphyEnglish,UserPhone,CreatedOn;
loginReq.onload = function() {
var json = this.responseText;
var response = JSON.parse(json);
var message = response.message;
var code = response.code;
if (response.data == null) {
alert("Message " + message + "code " + code);
} else {
var win1 = Titanium.UI.createWindow();
win1.open();
User = response.data.User;
UserName = User.UserLogin;
UserEmail = User.UserEmail;
UserFirstName = User.UserFirstName;
UserLastName = User.UserLastName;
UserAvatar = User.UserAvatar;
BioGraphyNative = User.BioGraphyNative;
BioGraphyEnglish = User.BioGraphyEnglish;
UserPhone = User.UserPhone;
CreatedOn = User.CreatedOn;
alert("UserName " + UserName + "UserEmail " + UserEmail);
}
};
loginReq.onerror = function() {
alert("Network error");
};
/*
* Login Button Click Event
*/
loginBtn.addEventListener('click',function(e) {
if (UserLogin.value !== '' && UserPassword.value !== '') {
var win1 = Titanium.UI.createWindow();
loginReq.open("POST", "url");
var params = {
UserLogin: UserLogin.value,
UserPassword: UserPassword.value
};
loginReq.send(params);
} else {
alert("Username/Password are required");
}
});
I am new in titanium, i f any body can helps me it will be very appreciated, and million ton thanks in advance.

Your window object is created but it's empty and has transparent background, so you don't see it on the screen.
You can change your onload to this:
loginReq.onload = function() {
var json = this.responseText;
var response = JSON.parse(json);
var message = response.message;
var code = response.code;
if (response.data == null) {
alert("Message " + message + "code " + code);
} else {
var win1 = Titanium.UI.createWindow({
backgroundColor: 'white',
layout: 'vertical',
});
var User = response.data.User;
for (var i in User) {
win1.add(Ti.UI.createLabel({ text: User[i] });
}
win1.open();
}
};
Also look out for JavaScript issues like declaring variable without var statement. Always use and try put all declaration at the beginning of function. To keep it monitored it's good have JSHint or JSLint installed and checking your code on every save.

Related

Delay for messages in node-telegram-bot-api

I am working on a telegram bot with the node-telegram-bot-api library. I made 2 buttons using keyboard. But when you click on them a lot, the bot will spam and sooner or later it will freeze. Is it possible to somehow put a delay for the user on messages.
if (text === '/start') {
return bot.sendMessage(chatId, 'hello', keyboardMain);
}
export const keyboardMain = {
reply_markup: JSON.stringify({
keyboard: [
[{
text: '/start',
},
],
resize_keyboard: true
})
};
You can create a user throttler using Javascript Map
/*
* #param {number} waitTime Seconds to wait
*/
function throttler(waitTime) {
const users = new Map()
return (chatId) => {
const now = parseInt(Date.now()/1000)
const hitTime = users.get(chatId)
if (hitTime) {
const diff = now - hitTime
if (diff < waitTime) {
return false
}
users.set(chatId, now)
return true
}
users.set(chatId, now)
return true
}
}
How to use:
You'll get the user's chatId from telegram api. You can use that id as an identifier and stop the user for given specific time.
For instance I'm gonna stop the user for 10seconds once the user requests.
// global 10 second throttler
const throttle = throttler(10) // 10 seconds
// in your code
const allowReply = throttle(chatId) // chatId obtained from telegram
if (allowReply) {
// reply to user
} else {
// dont reply
}
I tried using this code, put the function code in my function file, connected everything to the required file, and I don’t understand what to do next and where to insert the last code and what to do with it. I'm new to JavaScript and just learning.
import {
bot
} from '../token.js';
import {
throttler
} from '../functions/functions.js';
import {
keyboardMain
} from '../keyboards/keyboardsMain.js';
export function commands() {
bot.on('message', msg => {
const text = msg.text;
const chatId = msg.chat.id;
const throttle = throttler(10);
if (text === '/start') {
const allowReply = throttle(chatId) // chatId obtained from telegram
if (allowReply) {
return bot.sendMessage(chatId, 'hello', keyboardMain);
} else {
// dont reply
}
}
return bot.sendMessage(chatId, 'error');
});
}
Get the time when he pressed the button
Get the time of the next click
Take away the difference and set the condition (if, for example, more than 3 seconds have passed between clicks, then the user will not be frozen).
var token = ""; // FILL IN YOUR OWN TOKEN
var telegramUrl = "https://api.telegram.org/bot" + token;
var webAppUrl = ""; // FILLINYOUR GOOGLEWEBAPPADDRESS
var ssId = ""; // FILL IN THE ID OF YOUR SPREADSHEET
function getMe() {
var url = telegramUrl + "/getMe";
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function setWebhook() {
var url = telegramUrl + "/setWebhook?url=" + webAppUrl;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function sendText(id,text) {
var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + text;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function doGet(e) {
return HtmlService.createHtmlOutput("Hi there");
}
function doPost(e){
var data = JSON.parse(e.postData.contents);
var text = data.message.text;
var id = data.message.chat.id;
var msgbegan = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A7").getValue();
var msginfo = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A9").getValue();
var answer = "%0A" + msgbegan + "%0A" ;
///////////////////////
/*
* #param {number} waitTime Seconds to wait
*/
function throttler(waitTime) {
const users = new Map()
return (chatId) => {
const now = parseInt(Date.now()/1000)
const hitTime = users.get(chatId)
if (hitTime) {
const diff = now - hitTime
if (diff < waitTime) {
return false
}
users.set(chatId, now)
return true
}
users.set(chatId, now)
return true
}
}
// global 10 second throttler
const throttle = throttler(500) // 10 seconds
// in your code
const allowReply = throttle(chatId) // chatId obtained from telegram
if (allowReply) {
// reply to user
} else {
// dont reply
}
///////////////////////////////////////
if(text == "/start"){
sendText(id, answer);
} else if (text == "/info"){
sendText(id, msginfo);
}else{
if (text.length == 10){
var found = false;
var total_rows = SpreadsheetApp.openById(ssId).getSheets()[0].getMaxRows();
for(i=1; i<=total_rows; i++){
var loop_id = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(i,2).getValue();
if(text == loop_id){
found = true;
found_at = i; // employee row
break;
}
}
if(found){
sendText(id, work_message);
}else{
var msgerrror = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A6").getValue();
var not_found = "%0A" + msgerrror+ "%0A" ;
sendText(id, not_found);
}
} else {
sendText(id, "eroor");
}
}
/////////////
var emp_name = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,1).getValue();
var emp_work = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,3).getValue();
var homeloc = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,4).getValue();
var emp_location = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,8).getValue();
var emp_data = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,5).getValue();
var emp_day = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,6).getValue();
var emp_clock = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,7).getValue();
var emp_location = SpreadsheetApp.openById(ssId).getSheets()[0].getRange(found_at,8).getValue();
var welcome = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A2").getValue();
var msgemp = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A3").getValue();
var msgloc = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A4").getValue();
var msgbay = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A5").getValue();
var msghome = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A8").getValue();
var msmobil = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A11").getValue();
var mstoday = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A13").getValue();
var msdata = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A14").getValue();
var msclock = SpreadsheetApp.openById(ssId).getSheets()[1].getRange("A15").getValue();
var work_message = welcome + emp_name +
"%0A" + msgemp + emp_work +
"%0A" + mstoday + emp_day +
"%0A" + msdata + emp_data +
"%0A" + msclock + emp_clock +
"%0A" + msghome + homeloc +
"%0A" + msgloc+ emp_location +
"%0A" + msgbay +
"%0A" + msmobil ;
}
Excuse me . I am a beginner
Is this the correct way

JS user input function

So i am running a online chat function using js that currently sends and receives messages and has a user count in the top right corner that updates when a user leaves or joins. I need help with making a js function that you can submit a name to and it saves it and prints it alongside your own messages.
my current code on chat.js-
var WebSocketServer = require("ws").Server;
var wss = new WebSocketServer({port:3030});
var msgArray = new Array();
wss.on("connection", function(client) {
client.on("message", function(message) {
wss.clients.forEach(function(client) {
sendChat(client, message);
});
msgArray.push(message);
});
sendChat(client, `Welcome to chat :)`);
sendUC();
msgArray.forEach(function(item) {
sendChat(client, item);
})
});
function sendChat(client, message) {
var msg = ["chat", message];
client.send(JSON.stringify(msg));
}
function sendUC(){
wss.clients.forEach(function(client){
var UCmsg = ["uc",wss.clients.size];
client.send(JSON.stringify(UCmsg));
});
}
My current code on client.js-
var ws = new WebSocket("ws://jg.codesphere.net:3030");
ws.onmessage = function (payload) {
var msg = JSON.parse(payload.data);
if (msg[0] == "chat") {
addMessage(msg[1]);
}
if (msg[0] == "uc") {
addMessage("Another user joined");
adduc(msg[1]);
}
};
$(function () {
document.forms[0].onsubmit = function () {
var input = $("input#message").val();
$("input#message").val('');
ws.send(input);
};
});
function User() {
}
function addMessage(m) {
var html = "<p>" + m + "</p>";
$("div#messages").append(html);
}
function adduc(m) {
var html = "<p>" + m + "</p>";
$("span#1").html(m + " users online");
}
So i need help with where i would call a user entry function and how to make the function.

angularJs data binding issue to capture and display status

I am trying to get and display Total Sent, Total Success and Total Error using AngularJs. So far, I have been able to retrieve the information Total Sent, Total Success and Total Error inside the code. However, I am not convinced that the approach (using global variables) I have taken to bind and display those status is correct.
Here are my controller and associated services.
var sent = 0;
var succ = 0;
var err = 0;
myApp.service('ParseMessageService', function() {
this.myFunc = function(message) {
var res = message.match(/Success/g);
if (res !== null) {
//console.log(res);
TSent = message.match(/Total Sent: (\d+)/);
if (TSent) {
sent = TSent[1];
//parsedMsg.push(TSent[1]);
//console.log(TSent[1]); //replace with $scope and display on Gui
}
TSucc = message.match(/Total Success: (\d+)/);
if (TSucc) {
succ = TSucc[1];
//parsedMsg.push(TSucc[1]);
// console.log(TSucc[1]); //replace with $scope and display on Gui
}
TErr = message.match(/Total Errors: (\d+)/);
if (TErr) {
err = TErr[1];
//parsedMsg.push(TErr[1]);
//console.log(TErr[1]); //replace with $scope and display on Gui
}
}
}
//}
});
myApp.factory('WebSocketService', function() {
var service = {};
service.connect = function() {
if (service.ws) {
return;
}
var ws = new WebSocket("ws://127.0.0.1:8000");
ws.onopen = function() {
service.callback("Succeeded to open a connection");
//display webSocket connected status
};
ws.onerror = function() {
service.callback("Failed to open a connection");
}
ws.onmessage = function(message) {
service.callback(message.data);
};
service.ws = ws;
}
service.send = function(message) {
service.ws.send(message);
}
service.subscribe = function(callback) {
service.callback = callback;
}
return service;
});
angular.module('myApp')
.controller('PingTestController', function($scope, WebSocketService, ParseMessageService) {
$scope.messages = [];
$scope.TSent = [];
$scope.TSucc = [];
$scope.TErr = [];
$scope.parsedSent = 0;
$scope.parsedSucc =0;
$scope.parsedErr =0;
$scope.pingStr = "Ping"
$scope.define = "Definitions";
$scope.url = "www.google.com"
$scope.size = "1";
$scope.TTL = "10"
$scope.pause = "3";
$scope.paraStr = "[,]";
$scope.cmdStartStr = "[;]";
($scope.trueStr) = "TRUE";
($scope.falseStr) = "FALSE";
($scope.PfalseStr) = "False";
($scope.cmdEndStr) = "[/]";
//($scope.newLineStr) = "\r\n";
($scope.startCmd) = "Start";
($scope.stopCmd) = "Stop";
($scope.clearCmd) = "Clear";
$scope.updatePing = function() {
$scope.pingCmd = ($scope.cmdStartStr) + ($scope.pingStr) +
($scope.cmdStartStr) + ($scope.define) + ($scope.cmdStartStr) +
($scope.url) + ($scope.paraStr) + ($scope.PfalseStr) + ($scope.paraStr) +
($scope.TTL) + ($scope.paraStr) +
($scope.size) + ($scope.paraStr) +
($scope.pause) + ($scope.cmdEndStr);
}
WebSocketService.subscribe(function(message) {
ParseMessageService.myFunc(message);
$scope.parsedSent = (sent);
$scope.parsedSucc = (succ);
$scope.parsedErr= (err);
$scope.messages.push(message);
$scope.$apply();
});
$scope.connect = function() {
WebSocketService.connect();
}
$scope.send = function() {
WebSocketService.send($scope.pingCmd);
$scope.text = "";
}
//[;]Ping[;]Stop[;]TRUE[/]
$scope.stopPing = function() {
$scope.pingStop = ($scope.cmdStartStr) + ($scope.pingStr) +
($scope.cmdStartStr) + ($scope.stopCmd) + ($scope.cmdStartStr) +
($scope.trueStr) + ($scope.cmdEndStr);
WebSocketService.send($scope.pingStop);
}
// [;]Ping[;]Start[;]TRUE[/]
$scope.startPing = function() {
$scope.pingStart = ($scope.cmdStartStr) + ($scope.pingStr) +
($scope.cmdStartStr) + ($scope.startCmd) + ($scope.cmdStartStr) +
($scope.trueStr) + ($scope.cmdEndStr);
WebSocketService.send($scope.pingStart);
}
// [;]Ping[;]Clear;]TRUE[/]
$scope.clearPing = function() {
$scope.pingClear = ($scope.cmdStartStr) + ($scope.pingStr) +
($scope.cmdStartStr) + ($scope.clearCmd) + ($scope.cmdStartStr) +
($scope.trueStr) + ($scope.cmdEndStr);
WebSocketService.send($scope.pingClear);
}
});
Here is relevant part of html code.
<br/>
<button ng-click="send()" class="btn"> Add new Ping</button>
<button ng-click="startPing()" class="btn"> StartPing</button>
<button ng-click="stopPing()" class="btn">Stop Ping</button>
<button ng-click="clearPing()" class="btn">Clear Ping</button>
<br />
<div ng-repeat = "message in messages track by $index">
{{parsedSent}} {{parsedSucc}} {{parsedErr}}
</div>
Eventually, I would like to have a clean way to get those statistics and display with on a webpage i.e. Total success with green background, Total Error with Red and Total Sent with Blue background.
You can move the global variables to the service an use them from there. You could also use this answer: Static javascript variable to be used as counter in Angularjs controller

Send object id from success function to another function in parse.com

I have a problem on parse.com in which i to take the id of an type and pass it to another function which uploads an image. Then take the type.id among with the image and post it to another function which saves the data to a class.
This is what i've tried until now without success.
--OnClick code
$('#submitId').on("click", function(e, f) {
e.preventDefault();
typeSave(typeid1);
//var objnew1 = typeSave();
console.log("inside onclick " + type2);
var fileUploadControl = $("#profilePhotoFileUpload")[0];
var file = fileUploadControl.files[0];
var name = file.name; //This does *NOT* need to be a unique name
var parseFile = new Parse.File(name, file);
parseFile.save().then(
function() {
//typeSave();
type2 = typeid1;
saveJobApp(parseFile, type2);
console.log("inside save onclick " + type2);
},
function(error) {
alert("error");
}
);
});
-- Type Code
var type;
var typeid1;
var type2;
function typeSave() {
var type = new Parse.Object("type");
var user = new Parse.Object("magazia");
//var bID = objbID;
//user.id = bID;
var cafebar = document.getElementById('cafe_bar').checked;
if (cafebar) {
var valueCafebar = true;
} else {
var valueCafebar = false;
}
var club = document.getElementById('club').checked;
if (club) {
var valueClub = true;
} else {
var valueClub = false;
}
var restaurant = document.getElementById('restaurant').checked;
if (restaurant) {
var valueRestaurant = true;
} else {
var valueRestaurant = false;
}
var pistes = document.getElementById('pistes').checked;
if (pistes) {
var valuePistes = true;
} else {
var valuePistes = false;
}
type.set("cafebar", valueCafebar);
type.set("club", valueClub);
type.set("restaurant", valueRestaurant);
type.set("pistes", valuePistes);
type.save(null, {
success: function(type) {
//saveJobApp(type.id);
var typeid1 = type.id;
console.log("inside type save " + typeid1);
//return ;
},
error: function(type, error) {
alert('Failed to create new object, with error code: ' + error.description);
}
});
}
-- Send Data to parse.com class code
function saveJobApp(objParseFile, type2) {
var jobApplication = new Parse.Object("magazia");
var email = document.getElementById('email').value;
var name = document.getElementById('name').value;
var description = document.getElementById('description').value;
var website = document.getElementById('website').value;
var phone = document.getElementById('phone').value;
var address = document.getElementById('address').value;
var latlon = document.getElementById('latlon').value;
var area = document.getElementById('area').value;
var value = latlon;
value = value.replace(/[\(\)]/g, '').split(', ');
console.log("inside saveJobApp " + type2);
var x = parseFloat(value[0]);
var y = parseFloat(value[1]);
var point = new Parse.GeoPoint(x, y);
jobApplication.set("image", objParseFile);
jobApplication.set("email", email);
jobApplication.set("phone", phone);
jobApplication.set("address", address);
jobApplication.set("name", name);
jobApplication.set("website", website);
jobApplication.set("description", description);
jobApplication.set("area", area);
jobApplication.set("latlon", point);
jobApplication.set("typeID", type2);
jobApplication.save(null, {
success: function(gameScore) {
// typeSave(jobApplication.id);
},
error: function(gameScore, error) {
alert('Failed to create new object, with error code: ' + error.description);
}
});
}
So resuming i am trying when i click the button to first run the typesave() function, after when it posts the type on the type class in parse, to take to type.id from the success function and send it to the parseFile.save().then
and then to send the objectFile and the type2 (which is the type.id) it in saveJobApp and them to save it in class magazia
What i get from the console.logs is this
Which means that my code post to the type class and takes the type.id
but it doesnt send it to the magazia class via the parsefile save.
Any idea of what am i missing?
I noticed your mistake is not about the functions but about trying to pass the type.id as a string and not as a function in the saveJobApp function.
if you try making it like this
function saveJobApp(objParseFile , objtype) {
var jobApplication = new Parse.Object("magazia");
var type = new Parse.Object("type");
type.id = objtype;
jobApplication.set("typeID", type);
I think it will work.
And also update the onclick and the ParseFile save code to this
$('#submitId').on("click", function(e) {
typeSave();
});
function PhotoUpload(objtype){
var fileUploadControl = $("#profilePhotoFileUpload")[0];
var file = fileUploadControl.files[0];
var name = file.name; //This does *NOT* need to be a unique name
var parseFile = new Parse.File(name, file);
parseFile.save().then(
function() {
saveJobApp(parseFile, objtype);
},
function(error) {
alert("error");
}
);
}
And the success function in typeSave()
should be something like this
type.save(null, {
success: function(type) {
PhotoUpload(type.id);
},
Hope this helps :)

save email attachments using Thunderbird source

I would like to save email attachments using thunderbird source code. I got the following code in your forums..but its not working
alert("Messages selected: " + gFolderDisplay.selectedCount);
let enumerator = gFolderDisplay.selectedMessages;
for each (let msgHdr in fixIterator(enumerator, Ci.nsIMsgDBHdr)) {
var messageID = msgHdr.messageId;
alert("MessageID: " + messageID);
var subject = msgHdr.mime2DecodedSubject;
alert("Subject: " + subject);
MsgHdrToMimeMessage(msgHdr, null, function (aMsgHdr, aMimeMsg) {
try {
alert("Size of the message: " + aMimeMsg.size);
alert("Structure of the message:\n" + aMimeMsg.prettyString(true, undefined, true));
let attachments = aMimeMsg.allUserAttachments || aMimeMsg.allAttachments;
alert("Number of attachments: " + attachments.length);
for (let [index, att] in Iterator(attachments))
{
alert ("URL: " + att.url + " Name: " + att.name);
let ioService = Cc["#mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
let neckoURL = null;
neckoURL = ioService.newURI(att.url, null, null);
neckoURL.QueryInterface(Ci.nsIMsgMessageUrl);
let uri = neckoURL.uri;
let attInfo = new AttachmentInfo(att.contentType, att.url, att.name, uri, att.isExternal);
attInfo.save();
}
} catch (err) {
alert(err);
}
}, true, { examineEncryptedParts: true, });
}
Using above code i can able to go through the selected messages.but not saving the attachments.its showing number of attachments.
And also i would like to set my own labels for the selected mails. How i can i achieve this? Please help me out... Thanks in advance
working code
var enumerator = gFolderDisplay.selectedMessages;
for each (var msgHdr in fixIterator(enumerator, Components.interfaces.nsIMsgDBHdr)) {
msgHdr.setStringProperty("docuHive","dhivelabel");
MsgHdrToMimeMessage(msgHdr, null, function (aMsgHdr, aMimeMsg) {
try {
var attachments = aMimeMsg.allUserAttachments || aMimeMsg.allAttachments;
for (var [index, att] in Iterator(attachments))
{
var ioService = Components.classes["#mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var neckoURL = null;
neckoURL = ioService.newURI(att.url, null, null);
neckoURL.QueryInterface(Components.interfaces.nsIMsgMessageUrl);
var uri = neckoURL.uri;
var attInfo = new AttachmentInfo(att.contentType, att.url, att.name, uri, att.isExternal);
// getting the chrome directory
var file = Components.classes["#mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("AChrom", Components.interfaces.nsIFile);
var msguri = msgHdr.folder.getUriForMsg(msgHdr);
messenger = Components.classes["#mozilla.org/messenger;1"]
.createInstance(Components.interfaces.nsIMessenger);
alert(messenger);
messenger.saveAttachmentToFolder(att.contentType,att.url,"attachmentname.extension",msguri,file);
}
} catch (err) {
alert(err);
}
}, true, { examineEncryptedParts: true, });
}

Categories

Resources