I've been trying to submit a form that contains multiple inputs (texts and one image) but I'm unable to retrieve the image from request (Grails 3.0.4)
My create.gsp looks like this:
<g:uploadForm controller="advertisement" action="save">
<input name="name" type="text" id="advertisement_name" />
<input name="link" type="text" id="advertisement_url" />
<input id="add_banner_image" name="myimage" type="file" accept="image/png,image/jpeg" data-max-size="512000"/>
<g:submitButton name="save" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" value="Salvar anúncio">
</g:submitButton>
</g:uploadForm>
My browser shows the correct request payload:
------WebKitFormBoundarysaAgHUi2q9vTfkkY
Content-Disposition: form-data; name="name"
Filipe
------WebKitFormBoundarysaAgHUi2q9vTfkkY
Content-Disposition: form-data; name="link"
https://www.filipescosta.com
------WebKitFormBoundarysaAgHUi2q9vTfkkY
Content-Disposition: form-data; name="imagemlouca"; filename="exemplo.jpeg"
Content-Type: image/jpeg
------WebKitFormBoundarysaAgHUi2q9vTfkkY
Content-Disposition: form-data; name="save"
Salvar anúncio
My resources.groovy looks like this:
beans = {
multipartResolver (org.springframework.web.multipart.commons.CommonsMultipartResolver) {
maxUploadSize=2500000
}
}
And my application.yml looks like this:
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlets: html
taglib: none
staticparts: none
My Controller looks like this:
def save() {
println request.getFile('myimage')
println "Request class: ${request.class}"
[...]
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'advertisement.label', default: 'Advertisement'), advertisement.id])
redirect(uri:'/')
}
'*' { respond advertisement, [status: CREATED, formats:['html']] }
}
}
But in console, the println message is:
null
Request class: class org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest
Can anyone take a look and help me with some trick? I've been searching examples and I couldn't find anything that helps.
You define: attribute name="myimage"
and try get with Uppercase name -> request.getFile('myImage')
Well, I figured out what was going on.
I was trying to create a new object with String type, but I was sending an input file type as a parameter.
Then, after trying to set the input type String to a file type, the code broke and I wasn't able to print the value of request.getFile.
Related
Here is the PHP code for pg3.php:
<html>
<body>
<form method="post" action="pg3.php">
<h2><font color="red">::Welcome to Server1: 172.16.24.150::</font></h2>
<input type="text" name="user">
<input type="submit" value="Submit">
</body>
</html>
<?php
if(!empty($_POST["user"])){
echo $_POST["user"];
}
?>
I sent the following request:
curl --data "8\r\nuser=mehran\r\n0\r\n" --header "Transfer-Encoding: chunked" "http://172.16.17.10/pg3.php"
I got the following response:
<html>
<body>
<form method="post" action="pg3.php">
<h2><font color="red">::Welcome to Server1: 172.16.24.150::</font></h2>
<input type="text" name="user">
<input type="submit" value="Submit">
</body>
</html>
As the above shows, user=meh is not in the response, while it must be there if Transfer-Encoding works correctly.
What's the problem??
TNX.
See this example in the documentation:
You send a chunked POST with curl like this:
curl -H "Transfer-Encoding: chunked" -d "payload to send" http://example.com
You don't need to try to create the chunked encoded payload yourself. In your case:
curl --data "user=mehran" --header "Transfer-Encoding: chunked" "http://172.16.17.10/pg3.php"
is enough for curl to send:
POST / HTTP/1.1
...
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded
b
user=mehran
0
I am trying to write a very basic crawler. After receiving an HTTP response, I am using the select.rs crate to extract the URLs from the body for further crawling.
How can I extract these URLs from from the "document" which is the "body" part of the HTTP response using the "for-iteration"?
extern crate hyper;
extern crate select;
extern crate xhtmlchardet;
extern crate robotparser;
extern crate url;
use std::io::Read;
use Crawler::hyper::client::Client;
use Crawler::hyper::header::Connection;
use Crawler::select::document::Document;
use Crawler::select::predicate::*;
pub fn crawl(url: &str) {
//Opens up a new HTTP client
let client = Client::new();
//Creates outgoing request
let mut res = client.get(&*url)
.header(Connection::close())
.send().unwrap();
//Reads the response
let mut body = String::new();
res.read_to_string(&mut body).unwrap();
println!("Response: {}", res.status);
println!("Headers:\n{}", res.headers);
println!("Body:\n{}", body);
let document = Document::from_str(&*body);
for node in document.find(Attr("id", "hmenus")).find(Name("a")).iter() {
println!("{} ({:?})", node.text(), node.attr("href").unwrap());
}
}
The result of executing crawl for a URL like "um.ac.ir" is a full HTTP response with a body. I am trying to extract the hrefs from this output.
Response: 200 OK
Headers:
X-Content-Type-Options: nosniff
X-Frame-Options: sameorigin
Cache-Control: cache
Date: Tue, 27 Feb 2018 13:16:27 GMT
Vary: Accept-Encoding
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Transfer-Encoding: chunked
Pragma: no-cache
Server: GFW/2.0
Connection: close
Content-Type: text/html; charset=utf-8
Strict-Transport-Security: max-age=63072000; preload
Set-Cookie: POSTNUKESID=pnd2nuadgastqak5h6nop87c63; path=/
...
<div class="col-md-4">
<h3>سایر</h3>
<ul>
<li><a target="_blank" href="http://ftpnews.um.ac.ir/">سایت خبری ftp دانشگاه</a></li>
<li><a target="_blank" href="http://news.um.ac.ir/Topic96.html">گزینش دانشگاه </a></li>
<li><a target="_blank" href="http://herasat.um.ac.ir/index.php?lang=fa">مدیریت حراست دانشگاه </a></li>
<li><a target="_blank" href="http://mafakher.um.ac.ir/">مركز آثارمفاخر و اسناد دانشگاه</a></li>
<li><a target="_blank" href="http://intr.um.ac.ir/">مدیریت همكاری های علمی و بین المللی</a></li>
<li><a target="_blank" href="http://eva.um.ac.ir/"> مدیریت نظارت و ارزیابی دانشگاه</a></li>
<li><a target="_blank" href="http://saybanemehr.um.ac.ir/">سایت سایبان مهر</a></li>
<li><a target="_blank" href="http://faf.um.ac.ir/">بنیاد دانشگاهی فردوسی</a></li>
<li><a target="_blank" href="http://ads.um.ac.ir/">آگهي ها و تبليغات دانشگاه</a></li>
<li><a target="_blank" href="http://fumblog.um.ac.ir/">سامانه مدیریت وبلاگ</a></li>
<li><a target="_blank" href="http://basijasatid.um.ac.ir/">بسیج اساتید</a></li>
<li><a target="_blank" href="http://basij.um.ac.ir/">بسیج كاركنان</a></li>
<li><a target="_blank" href="http://nahad.um.ac.ir/">نهاد نمایندگی رهبری در دانشگاه</a></li>
</ul>
</div>
...
The problem is that the println!("{} ({:?})", node.text(), node.attr("href").unwrap()) doesn't output anything since the [...].iter() is not working correctly:
for node in document.find(Attr("id", "hmenus")).find(Name("a")).iter() {
println!("{} ({:?})", node.text(), node.attr("href").unwrap());
}
It seems that find(Attr("id", "hmenus")).find(Name("a")) isn't the right way for finding "href" tags from the body of the HTTP response.
I believe rewriting this part should fix the problem in my code, although it requires an overall knowledge of how select::document is working.
I assume you copied the Attr("id", "hmenus") from some example code. This is a filter predicate that matches an HTML node containing attribute id="hmenus". Your example page um.ac.ir does not contain any nodes with attribute id="hmenus". If you want the crawler to find all <a> nodes on the page, the filter predicate would be Name("a").
for node in document.find(Name("a")).iter() {
if let Some(href) = node.attr("href") {
println!("{} ({:?})", node.text().trim(), href);
}
}
I am trying to send form data to my server (Asp.net server), but when debugging the server only the typed information is received, but the files are not there.
This is my html page: (http://pastebin.com/KZERsepn)
<template>
<ai-dialog>
<ai-dialog-body>
<div>
<span>character name</span>
<input type="text" value.bind="user.name" />
</div>
<div>
<span>Youtube url:</span>
<input type="text" value.bind="user.YoutubeUrl" />
</div>
<div>
<span>ProfileImage:</span>
<input type="file" file.bind="user.ProfileImage" />
</div>
<div>
<span>CoverImage:</span>
<input type="file" file.bind="user.CoverImage" />
</div>
</ai-dialog-body>
<ai-dialog-footer>
<button click.trigger="controller.cancel()">Cancel</button>
<button click.trigger="controller.ok(user)">Ok</button>
</ai-dialog-footer>
</ai-dialog>
and this is how i am posting the data:(http://pastebin.com/7bVHZthE)
createUser(user) {
let model = new FormData();
model.append('Name', user.Name);
model.append('YoutubeUrl', user.YoutubeUrl);
model.append('ProfileImage', user.ProfileImage);
model.append('CoverImage', user.CoverImage);
return this.client.fetch('/api/createUser', {
method: "post",
body: model,
headers: {
'Access-Controll-Allow-Origin': '*',
'Accept': 'application/json'
}
});
}
But only the user.name and user.youtubeurl properties are sent to the server.
To post files, you must use a multipart/form-data
The trick to posting a multipart/form-data is (rather unintuitively) to force the content-type header to false. So try this:
return this.client.fetch('/api/createUser', {
method: "post",
body: model,
headers: {
'Content-type': '', // this is where the magic happens
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json'
}
});
My web service uses asp.net web api. Currently my api controller doesn't do anything because I want to inspect the post to see what I'm working with here.
You'll notice that I'm posting to localhost. That's because currently I'm only running the service app in the debugger so that I can inspect the post via a Watch.
My problem is that it doesn't seem like my post is going anywhere. The breakpoint that I've set on the Post void never gets hit when I submit the form from the webpage.
Am I misunderstanding how this is supposed to work here?
Controller
public class CashbackController : ApiController
{
// POST api/<controller>
public void Post([FromBody]string value)
{
}
}
Client web page
<form action="http://localhost:49474/api/Cashback" method="post">
<p>
API Key: <input type="text" name="_apikey" /><br />
Receipt No: <input type="text" name="_receipt" /><br />
Purchase Date: <input type="text" name="_date" /><br />
Cashback Total: <input type="text" name="_cashback" />
</p>
</form>
<p><input type="submit" value="Submit" /></p>
<script>
$(document).ready(function() {
alert("JQuery works");
});
$("input[type=submit]").on("click", function () {
$("form").submit();
});
$("form").submit(function () {
$.post($(this).attr("action"), $(this).serialize(), function(data) {
if (!data.IsOK) {
alert("Error: " + data.Error);
}
else
{
alert("Post successful.");
}
return;
});
return false;
});
</script>
EDIT
Inspecting with fiddler, it doesn't look as though my clicking on the submit button is doing anything at all...
Correctly referenced jquery and fiddler caught this:
POST http://localhost:49474/api/Cashback HTTP/1.1
Host: localhost:49474
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: /
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost/servicepost/
Content-Length: 85
Origin: http://localhost
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
_apikey=abcdefghijklmnopqrstuvwxyz&_receipt=1234567890&_date=2015-03-31&_cashback=100
However, in my controller, value is still null
Mkay so there were a few things wrong here...
First, I hadn't referenced the correct jquery source
NOTE: Only ever use the googleapis link(this one is to jquery 2.1.3.min) or another such link as you see fit. It's just simpler
Secondly, my controller wasn't accepting the correct type. Now this is where I really got confused because the client app isn't going to know what models my api uses.
Turns out it's just a matter of mirroring the model on the client app that posts to the api. So consider the following
public class UserController : ApiController
{
// POST api/<controller>
public void Post([FromBody]User Value)
{
}
}
public class User
{
public int ID { get; set; }
public string Username { get; set; }
public string EmailAddress { get; set; }
}
The form must post a mirror of the model which in this case would look something like this:
<form method="post" action="path-to-service/api/User">
<div>
Username: <input type="text" name="Username" /><br />
Email Address: <input type="text" name="EmailAddress" />
</div>
</form>
The ajax post above will work but will need to be modified to do exactly what you want it to. Typically I just throw in some error handling into at if statement and a redirect into the else.
I have some trouble with the ICS attachment to Gmail/Google calendar addresses.
When I have to edit an event I send an update by mail with an ICS file with the same UID of the original event. However, GCalendar adds a second event. How can I overcome this?
This is first ICS file content:
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20130425T090000
DTEND:20130425T100000
DTSTAMP:20130206T101100
ORGANIZER;CN=Test test:mailto:test#test.com
ATTENDEE:test#test.eu
UID:CALEVENT_TS090519840000000005
DESCRIPTION:test
SUMMARY:test
LOCATION:Test
SEQUENCE:1
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
And this is the update ICS file content:
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20130425T100000
DTEND:20130425T110000
DTSTAMP:20130206T101100
ORGANIZER;CN=Test test:mailto:test#test.com
ATTENDEE:test#test.eu
UID:CALEVENT_TS090519840000000005
DESCRIPTION:test
SUMMARY:test
LOCATION:Test
SEQUENCE:2
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
When I receive the update files and I click on "add this event to calendar" I will find two different events.
This is the original raw email:
Delivered-To: test#test.eu
Received: by 10.216.231.19 with SMTP id k19csp190640weq;
Sat, 9 Feb 2013 08:01:11 -0800 (PST)
X-Received: by 10.194.7.136 with SMTP id j8mr15530679wja.38.1360425671327;
Sat, 09 Feb 2013 08:01:11 -0800 (PST)
Return-Path: <test#test.eu>
Received: from mxavas8.aruba.it (mxavas8.aruba.it. [62.149.157.18])
by mx.google.com with SMTP id 45si59706250eeg.83.2013.02.09.08.01.11;
Sat, 09 Feb 2013 08:01:11 -0800 (PST)
Received-SPF: neutral (google.com: 62.149.157.18 is neither permitted nor denied by best guess record for domain of test#test.eu) client-ip=62.149.157.18;
Authentication-Results: mx.google.com;
spf=neutral (google.com: 62.149.157.18 is neither permitted nor denied by best guess record for domain of test#test.eu) smtp.mail=test#test.eu
Received: (qmail 4991 invoked by uid 89); 9 Feb 2013 16:01:10 -0000
Delivered-To: test.eu-test#test.eu
Received: (qmail 4424 invoked by uid 89); 9 Feb 2013 16:01:04 -0000
Received: from unknown (HELO mxcmd03.ad.aruba.it) (10.10.10.67)
by mxavas8.ad.aruba.it with SMTP; 9 Feb 2013 16:01:04 -0000
Received: from smtpdg11.aruba.it ([62.149.158.229])
by mxcmd03.ad.aruba.it with bizsmtp
id yFwi1k01A4xF4Fy01G14N7; Sat, 09 Feb 2013 17:01:04 +0100
Received: from localhost ([79.54.181.227])
by smtpcmd04.ad.aruba.it with bizsmtp
id yG141k0074umbYX01G140P; Sat, 09 Feb 2013 17:01:04 +0100
Date: Sat, 9 Feb 2013 17:01:04 +0100
Return-Path: test#test.eu
To: test#test.eu
From: Event notification <test#test.eu>
Reply-To: Event notification <test#test.eu>
Subject: New Event
Message-ID: <238497c6d05cffae45716486e74a8009#localhost>
X-Priority: 3
X-Mailer: PHPMailer 5.2.2 (http://code.google.com/a/apache-extras.org/p/phpmailer/)
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="b1_238497c6d05cffae45716486e74a8009"
X-Spam-Rating: mxavas8.ad.aruba.it 1.6.2 0/1000/N
--b1_238497c6d05cffae45716486e74a8009
Content-Type: multipart/alternative;
boundary="b2_238497c6d05cffae45716486e74a8009"
--b2_238497c6d05cffae45716486e74a8009
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
test
DateTimeRoom
02/05/201309.00 - 10.15ROOM1
--b2_238497c6d05cffae45716486e74a8009
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<style type="text/css">
<!--
td{ background-color: #eee; }
-->
</style>
</head>
<body style="font-family: Arial, Helvetica, sans-serif; color: #333;">
<p style="text-align:center;"><img src="images/logo2.png" alt="Logo" /></p>
<hr style="border: 1px solid #ccc; width: 80%;" />
<div style=" width: 80%; margin: 10px auto;">
<h4></h4>
<h3>test</h3>
<table style="width: 400px; table-layout: fixed; border: 1px solid #ccc;">
<tr><th>Date</th><th>Time</th><th>Room</th></tr>
<tr><td>02/05/2013</td><td>09.00 - 10.15</td><td>ROOM 1</td></tr>
</table>
</div>
</body>
</html>
--b2_238497c6d05cffae45716486e74a8009--
--b1_238497c6d05cffae45716486e74a8009
Content-Type: text/calendar; name="event.ics"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="event.ics"
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:tsCalendar
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20130502T090000
DTEND:20130502T101500
DTSTAMP:20130209T170100
ORGANIZER:mailto:test#test.eu
ATTENDEE:mailto:test#test.eu
UID:CALEVENT_TS090519840000000013
DESCRIPTION:test
SUMMARY:test
LOCATION:ROOM1 (floor: prova)
SEQUENCE:1
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
--b1_238497c6d05cffae45716486e74a8009--
Here are the other tests with the ORGANIZER email the same as the Sender email and ATTENDEE email the same as Receiver email.
Creating http://tny.cz/6396ba62
Updating http://tny.cz/08ac81c0
Some of the answers provided are not (entirely) correct.
In short, your ATTENDEE property needs more arguments to make sure Google Calendar considers it an update:
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;CN=Recipient Name;X-NUM-GUESTS=0:mailto:recipient#gmail.com
I had the same problem and to find the answer I:
Sent myself an invitation using Google Calendar itself + an updated invitation
Compared the two .ics files
Ran many different self-generated variations on those two .ics files to find out which parameters were really necessary
These are my findings:
Increment SEQUENCE from 0 to 1 (or further if you want to update updates)
METHOD has to be REQUEST (*1)
Email sender does NOT need to be the same as ORGANIZER (Sidenote: It is however, not possible in Google Calendar to update an ORGANIZER)
ORGANIZER does NOT need to be listed as an ATTENDEE
Email recipient has to be an ATTENDEE
Also (as mentioned above), the ATTENDEE needs additional parameters, not just :mailto
STATUS does NOT need to be provided. EDIT: This is the case when sending invites to google calendar / chrome / mac, but the invite doesn't get a proper preview in other combinations it seems
Arguments that take several lines in the doc should be indented by one space on the next line
In iCalender objects generated by Google Calendar you may notice that lines that are too long are broken into several lines into the document, however this is not required (e.g. you can provide a description that is a very long string, just make sure it only takes one line or cut it in lines where every line is indented with one space)
Bonus Tip: Use same UID in original invite and update (this is actually not required BUT makes sure your historical test results remain unaffected...)
Bonus Tip 2: for easier testing, also change the SUMMARY and subject of your email each time
Cleaned up example:
BEGIN:VCALENDAR
PRODID:-//YourCompany/AppName//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20180331T150000
DTEND:20180331T160000
DTSTAMP:20180331T150000 // make sure to populate this dynamically
ORGANIZER;CN=organizer#gmail.com:mailto:organizer#gmail.com
UID:BESTIDEVER123
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;CN=Recipient Name;X-NUM-GUESTS=0:mailto:recipient#gmail.com
CREATED:20180331T150000 // make sure to populate this dynamically
DESCRIPTION:Best event evah
LAST-MODIFIED:20180331T150000 // make sure to populate this dynamically
LOCATION:
SEQUENCE:0 // don't forget to increment this!!
SUMMARY:A Wonderful Event
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
(*1) The only question that I could not figure out is how to have a METHOD:PUBLISH that can be updated - I am trying to make a calendar publishing app that should NOT take replies. If anyone can figure that out I would be very grateful. :-)
see RFC5546 Update an Event
The event is moved to a different time. The combination of the "UID"
property (unchanged) and the "SEQUENCE" (bumped to 1) properties
indicate the update.
in your case given what you shared you probably need to add a SEQUENCE property in your ical file and increment it for every update you make.
Update:
given the ical file you added, you are missing the organiser and attendee fields with below file the update work
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:pyICSParser
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20130425T090000
DTEND:20130425T100000
DTSTAMP:20130206T101100
ORGANIZER:mailto:organiser#example.com
ATTENDEE:mailto:attendee#example.com
UID:CALEVENT_TS090519840000000005
DESCRIPTION:test
SUMMARY:test
LOCATION:Test
SEQUENCE:1
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
Also you need to match the email address of the sender with the one from organiser and same about the attendee, something like below has been validated with google calendar.
eml_as_string:
Subject: New Event
Message-ID: <238497c6d05cffae45716486e74a8009#localhost>
X-Priority: 3
X-Mailer: PHPMailer 5.2.2 (http://code.google.com/a/apache-extras.org/p/phpmailer/)
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="b1_238497c6d05cffae45716486e74a8009"
X-Spam-Rating: mxavas8.ad.aruba.it 1.6.2 0/1000/N
--b1_238497c6d05cffae45716486e74a8009
Content-Type: multipart/alternative;
boundary="b2_238497c6d05cffae45716486e74a8009"
--b2_238497c6d05cffae45716486e74a8009
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
test
DateTimeRoom
02/05/201309.00 - 10.15ROOM1
--b2_238497c6d05cffae45716486e74a8009
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<style type="text/css">
<!--
td{ background-color: #eee; }
-->
</style>
</head>
<body style="font-family: Arial, Helvetica, sans-serif; color: #333;">
<p style="text-align:center;"><img src="images/logo2.png" alt="Logo" /></p>
<hr style="border: 1px solid #ccc; width: 80%;" />
<div style=" width: 80%; margin: 10px auto;">
<h4></h4>
<h3>test</h3>
<table style="width: 400px; table-layout: fixed; border: 1px solid #ccc;">
<tr><th>Date</th><th>Time</th><th>Room</th></tr>
<tr><td>02/05/2013</td><td>09.00 - 10.15</td><td>ROOM 1</td></tr>
</table>
</div>
</body>
</html>
--b2_238497c6d05cffae45716486e74a8009--
--b1_238497c6d05cffae45716486e74a8009
Content-Type: text/calendar; name="event.ics"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="event.ics"
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:tsCalendar
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20130502T090000
DTEND:20130502T101000
DTSTAMP:20130209T170100
ORGANIZER:mailto:test#test.eu
ATTENDEE:mailto:test#test.eu
UID:CALEVENT_TS090519840000000013
DESCRIPTION:test
SUMMARY:test
LOCATION:ROOM1 (floor: prova)
SEQUENCE:1
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR
--b1_238497c6d05cffae45716486e74a8009--
on which below script was applied:
# -*- coding:utf-8 -*-
import smtplib
def sendInvite(fro,to,emlasstring):
mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(login, password)
mailServer.sendmail(fro, to, emlasstring)
mailServer.close()
newUID = "UID:newCALEVENT_TS090519840000000016"
#needed to change UID as once an event was sent its UID is locked and a few attempts were needed to make the script work
eml = open("SO14712929_1.eml",'r').read()
emlhead = "To: "+attendee_eml+CRLF
emlhead += "From:"+fro+CRLF
emlhead += "Reply-To: "+fro+CRLF
eml = emlhead+eml
eml = eml.replace("ORGANIZER:mailto:test#test.eu","ORGANIZER:mailto:"+fro_eml)
eml = eml.replace("ATTENDEE:mailto:test#test.eu","ATTENDEE:mailto:"+attendee_eml)
eml = eml.replace("UID:CALEVENT_TS090519840000000013",newUID)
sendInvite(fro,attendees,eml)
print "invite sent"
eml = open("SO14712929_2.eml",'r').read()
emlhead = "To: "+attendee_eml+CRLF
emlhead += "From:"+fro+CRLF
emlhead += "Reply-To: "+fro+CRLF
eml = emlhead+eml
eml = eml.replace("ORGANIZER:mailto:test#test.eu","ORGANIZER:mailto:"+fro_eml)
eml = eml.replace("ATTENDEE:mailto:test#test.eu","ATTENDEE:mailto:"+attendee_eml)
eml = eml.replace("UID:CALEVENT_TS090519840000000013",newUID)
sendInvite(fro,attendees,eml)
print "updated invite sent"
Try with METHOD:PUBLISH instead of METHOD:REQUEST